Hi,
I am new to .NET framework. I am trying to get data from the third
party web application using WebHTTPRequest and Response class. I am
getting TimeOut exception at GetResponse Method..
Dim objResponse As HttpWebResponse = objRequest.GetR esponse()
tried out different solutions but still problem persist. Here is the
code from my test applicaiton
Thanks,
--James
=============== =============== =============== =============== =============== ==
Private Function readHtmlPage(By Val Url As String)
Dim result As String = ""
Dim strPost As String = txtRequest.Text
Dim myWriter As StreamWriter
Dim objRequest As HttpWebRequest = WebRequest.Crea te(Url)
objRequest.Meth od = "POST"
objRequest.Cont entLength = strPost.Length
objRequest.Cont entType = "applicatio n/x-www-form-urlencoded"
Dim c As X509Certificate s.X509Certifica te
Try
c = X509Certificate s.X509Certifica te.CreateFromCe rtFile("C:\MyFo lder\xyz.cer")
objRequest.Clie ntCertificates. Add(c)
Debug.Write("Cl ient cert added. Name: " & c.GetName)
myWriter = New StreamWriter(ob jRequest.GetReq uestStream())
myWriter.Write( strPost, 0, strPost.Length)
Catch e As Exception
Return e.Message
txtResponse.Tex t = e.Message
Finally
'myWriter.Close ()
End Try
'
Try
Dim objResponse As HttpWebResponse =
objRequest.GetR esponse()
Dim sr As StreamReader
sr = New StreamReader(ob jResponse.GetRe sponseStream())
result = sr.ReadToEnd()
sr.Close()
txtResponse.Tex t = result
Return result
Catch e As Exception
Return e.Message
End Try
End Function
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
As System.EventArg s) Handles Button1.Click
txtResponse.Tex t =
readHtmlPage("h ttps://mywebpage.com/myApplicaiton.e xe")
End Sub 1 9462
There are a couple of issues with your code.
First, you are setting the content length = "strPost.Length " . But then you
are using a StreamWriter to write the data. Sometimes you could end up with
a mismatch between the lengths of data you set in the content-length, and
the data actually written by the StreamWriter, esp if the encodings dont
match.
What you should do is:
byte [] rawbytes = Encoding.ASCII. GetBytes(strPos t);
req.ContentLeng th = rawbytes.Length ;
...
Stream rq = req.GetRequestS tream();
rq.Write(rawbyt es,0,rawbytes.L ength);
rq.Close();
...
Secondly, you are not closing the response object. Since the StreamReader
you attached to the response stream does not own the underlying stream, it
wont close the stream when you close the StreamReader. You must close the
stream, or just call response.Close( ).
feroze
=============== ========
this posting is provided as-is, it provides no guarantees and confers no
rights.
=============== ========
"James" <ni*******@yaho o.com> wrote in message
news:65******** *************** **@posting.goog le.com... Hi,
I am new to .NET framework. I am trying to get data from the third party web application using WebHTTPRequest and Response class. I am getting TimeOut exception at GetResponse Method..
Dim objResponse As HttpWebResponse = objRequest.GetR esponse()
tried out different solutions but still problem persist. Here is the code from my test applicaiton
Thanks, --James
=============== =============== =============== =============== =============== =
= Private Function readHtmlPage(By Val Url As String)
Dim result As String = "" Dim strPost As String = txtRequest.Text Dim myWriter As StreamWriter Dim objRequest As HttpWebRequest = WebRequest.Crea te(Url)
objRequest.Meth od = "POST" objRequest.Cont entLength = strPost.Length objRequest.Cont entType = "applicatio n/x-www-form-urlencoded"
Dim c As X509Certificate s.X509Certifica te
Try c =
X509Certificate s.X509Certifica te.CreateFromCe rtFile("C:\MyFo lder\xyz.cer") objRequest.Clie ntCertificates. Add(c) Debug.Write("Cl ient cert added. Name: " & c.GetName)
myWriter = New StreamWriter(ob jRequest.GetReq uestStream()) myWriter.Write( strPost, 0, strPost.Length) Catch e As Exception Return e.Message txtResponse.Tex t = e.Message Finally
'myWriter.Close ()
End Try
' Try
Dim objResponse As HttpWebResponse = objRequest.GetR esponse() Dim sr As StreamReader sr = New StreamReader(ob jResponse.GetRe sponseStream()) result = sr.ReadToEnd() sr.Close()
txtResponse.Tex t = result Return result Catch e As Exception Return e.Message End Try
End Function
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
txtResponse.Tex t = readHtmlPage("h ttps://mywebpage.com/myApplicaiton.e xe")
End Sub This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: IIS的响应时间问题,急!!!多谢无 |
last post by:
i distribute a website on IIS which is programmed with C# HttpHandler,then i
pragram a Winform client to send empty call to the website and record the
time that the call return to client.
when the webform and website are both on the same machine,it will waste
below 50 millisecond.
but when the webform is on other machine in the same local network,it will
waste above 150 millisecond.
why?it's a urgent problem,please help me and tell me how...
|
by: Troy |
last post by:
I have a class library (DLL) that I created and have been using for sometime in my various .NET applications. Recently, I have been having problems with what I believe is corruption (or a bug) of the DLL. The problem goes something like this:
- I add new classes, methods, types, etc to the class library DLL and compile. The compile completes successfully with no errors or warnings
- In the app that references this dll, I can use the new...
|
by: IIS的响应时间问题,急!!!多谢无 |
last post by:
i distribute a website on IIS which is programmed with C# HttpHandler,then i
send empty call to the website and record the time that the call return to
client.
1、when the client is C# Winform, it waste about 75 millisecond if website
and the client are both on the same machine or are on different machine in
the same local network.
2、when the client(IE) is C++ ActiveX Control,it waste about 75 millisecond
if the client and the...
|
by: dotnettester |
last post by:
Hi,
I am using Response.writefile to write a file into clients browser. It works
fine with files upto 60MB. When I come across a file size bigger than that,
it break with error saying page can not be displayed.
Any clue?
|
by: Britney |
last post by:
Hi guys,
in my default.aspx file, I have following code.
when I go to browser, I enter values in both textboxs, then I hit submit
Button,
however, it didn't go to page2.aspx. instead, it was still in default page.
I thought Action will direct page to page2.aspx, no???
<form id="Form1" method="post" runat="server" action="page2.aspx">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
| |
by: idikoko |
last post by:
I have a small problem I am trying to extract charcters from one string
store it in another and then compare the new string and out a msg. The
code looks fine but it always runs into a compiler problem. please help
here is the code:
// LexicalScanner.cpp : Defines the entry point for the console
application.
//
#include <iostream>
#include "stdafx.h"
|
by: James |
last post by:
Hi,
I am new to .NET framework. I am trying to get data from the third
party web application using WebHTTPRequest and Response class. I am
getting TimeOut exception at GetResponse Method..
Dim objResponse As HttpWebResponse = objRequest.GetResponse()
tried out different solutions but still problem persist. Here is the
|
by: KusoYumi |
last post by:
Hello, im facing date and time problem. I want get a time in Date Type, with this format HH:mm:SS
i try to get new Date(), then format it as String. Then i use substring to get the time. Then i parse it as Date Type, and want to save it in database(database has a field called start_time, which is Date Type)
After i do this transaction and check with database, database show "1970-01-01 17:12:00".....Can anyone help me on that?Thanks in advanced
|
by: Rainy |
last post by:
Hello!
I'm having some trouble with pyserial package, I'm sending commands
and reading responses from a custom pcb, and sometimes I get a proper
response, at other times I get nothing, and sometimes I get about half
of the response string with beginning cut off. About half the time an
empty string is returned, the other ~half time good response, and more
rarely I get partial response.
When I try to use the same Serial instance to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |