Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

http post

Status
Not open for further replies.

dinger2121

Programmer
Sep 11, 2007
439
US
Hello,
I am trying to replicate an http post to a cgi script using c#. I have an html page with a file control throug which I browse to an xml file and that xml file is then uploaded to a server and the xml file is processed. Below is the html code that successfully submits the file along with the values -

Code:
<html>
	<head><title>Upload xml</title></head>
	<body>
		<form method="POST" enctype="multipart/form-data" action="[URL unfurl="true"]https://somewebserver/somefolder">[/URL]
			<table>
				<tr><td>Username:  </td><td><input type=text name=username></td></tr>
				<tr><td>Password:  </td><td><input type=password name=password></td></tr>
				<tr><td>XML File:  </td><td><input type=file name=xmlfile></td></tr>
			</table>
			<input type="radio" name=processtype value="processA">Type A<br />
			<input type="radio" name=processtype value="processB">Type B<br />
			<input type="radio" name=processtype value="processC">Type C<br />
			<input type="submit" value="Process File">
		</form>
	</body>
</html>


I have the C# code below to process this file -
Code:
string filename = @"c:\myfile.xml";
            string uri = "[URL unfurl="true"]https://somewebserver/somefolder";[/URL]

            WebClient client = new WebClient();
            
            NameValueCollection coll = new NameValueCollection();
            coll.Add("Content-type", "text/xml");
            //coll.Add("Content-type", "multipart/form-data");
            coll.Add("username", "myUser");
            coll.Add("password", "myPass");
            coll.Add("processtype","processA");
            coll.Add("xmlfile", filename);
            

            byte[] resp = client.UploadValues(uri, "POST", coll);
            Console.WriteLine(Encoding.ASCII.GetString(resp));

When I run this code, I get the response -

/filelocation/null already exists on server.

I look on the server, and there is a file named null that exists. This leads me to believe that the filename/contents are getting lost in the upload, but I don't know where. If anyone has any thoughts regarding how to accomplish this, they would be greatly appreciated.

carl
MCSD, MCTS:MOSS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top