473,746 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

500 status in webrequest

Hi guys,

when i use winhttp, and the server returns status 500, I get the text
that the server returned anyway...

when i use webrequest, and the server returns status 500, webrequest
just throws an exception... How can i find the text that came back with
the 500 status?

I need this because i am posting to a web service, that returns soap
fault in xml format.

any help would be appreciated. below is my webrequest code:
Public Function URL_POSTDATA(By Val URL As String, ByVal PostData As
String, Optional ByVal RequestHeaders As Hashtable = Nothing, Optional
ByVal UserName As String = "", Optional ByVal Password As String = "")
As String

Dim result As System.Net.WebR esponse
Dim html As String = ""
Dim rex As Exception = Nothing

Dim req As System.Net.WebR equest
Dim RequestStream As System.IO.Strea m
Dim ReceiveStream As System.IO.Strea m
Dim encode As System.Text.Enc oding
Dim sr As System.IO.Strea mReader
Dim nc As System.Net.Netw orkCredential

req = System.Net.WebR equest.Create(U RL)
req.Method = "POST"
req.ContentType = "applicatio n/x-www-form-urlencoded"

If Not RequestHeaders Is Nothing Then
For Each Header As String In RequestHeaders. Keys
If Header.ToLower = "content-type" Then
req.ContentType = RequestHeaders( Header)
req.Headers.Add (Header, RequestHeaders( Header))
End If
RequestHeaders = Nothing
End If

If UserName <> "" Then
nc = New System.Net.Netw orkCredential(U serName,
req.Credentials = nc
End If

Dim SomeBytes() As Byte
Dim UrlEncoded As New System.Text.Str ingBuilder
'Dim reserved() As Char = {ChrW(63), ChrW(61), ChrW(38)}

SomeBytes = System.Text.Enc oding.UTF8.GetB ytes(PostData)
req.ContentLeng th = SomeBytes.Lengt h
RequestStream = req.GetRequestS tream()
RequestStream.W rite(SomeBytes, 0, SomeBytes.Lengt h)
RequestStream.C lose()
result = req.GetResponse ()
ReceiveStream = result.GetRespo nseStream()
encode = System.Text.Enc oding.GetEncodi ng("utf-8")
sr = New System.IO.Strea mReader(Receive Stream, encode)

Dim read(256) As Char
Dim count As Integer = sr.Read(read, 0, 256)

Do While count > 0
html &= New String(read, 0, count)
count = sr.Read(read, 0, 256)

Catch Exc As Exception
rex = Exc
If Not result Is Nothing Then
End If
End Try

If Not rex Is Nothing Then
Err.Raise(1, "URL_POST() ", "Network Error: The request URI
could not be loaded or was malformed: " & rex.Message)
End If

Return html

End Function

Mar 24 '06 #1
0 1201

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: James Johnson | last post by:
Dear C#dex, I define a variable: HttpWebRequest webRequest and run the following request webRequest = WebRequest.Create(TARGET_URL) as HttpWebRequest; The webRequest object returns values and in the debugger I can see the value I want in the property
by: Paul | last post by:
Hello, First I want to refer to the problem "WebRequest : execute a button" of a few days ago. The way I solved it, I loose my session, and as a consequence my session variables. I don't want to keep those variables, as an alternative, as ViewState variables because I don't want to transfer to many hidden fields. This is the code I use :
by: John K. | last post by:
Hi I was wondering if it's possible to use the WebRequest class to access a file on windows shared folder with authentication? If yes, what would the syntax be? I've tried to look this up in the references available but to no avail Also, is it safer (better practise) in an LAN environment to use HTTP requests to access shared files (via ASP.NET) rather than UNC file shares TIA Regards John
by: ThyRock | last post by:
I am working on a WebRequest accessing the US Postal Service WebTools test API. This service uses a DLL file (ShippingAPITest.dll) with a query string which includes XML. The web service accepts the query string with no url encoding. I must pass the <> characters as they are in the query string. If these characters are url encoded the service rejects the request. This API Url is http://testing.shippingapis.com/ShippingAPITest.dll
by: kkb | last post by:
Hello! First, I'm sorry because of my english... I'll try to be understandable! I've got a strange problem using .NET 2003 C# and I haven't figured it out for a long time. I'm implementing an application to download images using System.NET classes (webclient, webrequest) asynchronously behind proxy server. The reading method works like this: System.Net.WebClient client=new System.Net.WebClient();
by: Mr Flibble | last post by:
OK I logon to a web site and I manage to get an SMSESSION cookie that I then store in a variable called _session (a class scoping variable). I do this by calling a logon URL and setting a cookie to SMCHALLANGE=YES to allow me to obtain a session. I then iterate the cookie collection to extract the SMSESSION value. All is good (so far). This is when the sky turns grey and the rain starts to fall. I then use this SMSESSION in a web...
by: eSolTec, Inc. 501(c)(3) | last post by:
Thank you in advance for any and all assistance. I'm trying to create a call to a web page to validate and register software. The code I'm using is: Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click Dim WebRequest As HttpWebRequest Dim instance As HttpWebRequest =...
by: Dave | last post by:
string m_request = some_web_page; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_request ); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Which works fine, but I need to set and send a cookie with the WebRequest. How do I do that?
by: darrel | last post by:
I swear I've read you can do this somewhere before, but don't recall where or what it'd even be called to do the correct googling. What I've been asked to do is make a 'dashboard' app that checks the status of various servers. If they are down, show an error. I found/modified this snippet: ---
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s 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: 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 project—planning, coding, testing, and deployment—without 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: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.