dinger2121
Programmer
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 -
I have the C# code below to process this file -
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
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