c# - Web Service that handles file upload works locally but not remote -
i've written webservice in servicestack accepts file uploads. test i've used following code:
string filepath = @"c:\myfile.pdf"; string webapi = @"http://localhost:20938/upload/myfile.pdf"; httpwebrequest client = (httpwebrequest)webrequest.create(webapi); client.method = webrequestmethods.http.post; client.allowwritestreambuffering = false; client.sendchunked = true; client.contenttype = "multipart/form-data;"; client.timeout = int.maxvalue; using (filestream filestream = file.openread(filepath)) { filestream.copy(client.getrequeststream()); } var response = new streamreader(client.getresponse().getresponsestream()).readtoend();
this works localhost, when deploy remote server, doesn't work. 500 internal error. (other web api calls return json data work locally , remotely).
how fix/debug this?
the code below, works me. difference, can see allowwritestreambuffering = true;
string requesturi = path.combine(serverip + @"/upload/", filename); httpwebrequest client = (httpwebrequest)webrequest.create(requesturi); client.method = webrequestmethods.http.post; client.allowwritestreambuffering = true; client.sendchunked = true; client.contenttype = "multipart/form-data;"; client.timeout = int.maxvalue; using (filestream filestream = file.openread(filepath)) { filestream.copy(client.getrequeststream()); } var response = new streamreader(client.getresponse().getresponsestream()).readtoend();
do have firewall, blocking port ?
Comments
Post a Comment