473,811 Members | 4,039 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

Try
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)
Else
req.Headers.Add (Header, RequestHeaders( Header))
End If
Next
RequestHeaders = Nothing
End If

If UserName <> "" Then
nc = New System.Net.Netw orkCredential(U serName,
Password)
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)
Loop

Catch Exc As Exception
rex = Exc
Finally
If Not result Is Nothing Then
result.Close()
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 1206

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

Similar topics

17
7243
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
3
6353
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 :
8
2407
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
12
2871
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
2
5979
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();
1
8207
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...
3
9605
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 =...
3
8189
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?
7
2664
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: ---
0
9604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10379
jinu1996
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...
1
10394
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10127
tracyyun
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...
0
9201
agi2029
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...
1
7665
isladogs
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...
0
6882
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();...
0
5552
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4336
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 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.