This is a discussion on HTTPWebRequest in webservice within the ASP and ASP.NET Programming forums, part of the Web Development category; Hi friends, I need to upload my files in to server through a webservice. Can I use HTTPWebRequest for that? ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi friends, I need to upload my files in to server through a webservice. Can I use HTTPWebRequest for that? And how to upload using this HTTPWebRequest? Could anybody help me?
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
| Sponsored Links |
| |||
| yes buddy, You can use HTTPWebRequest for your uploading process. check with my coding is in below. Code: try
{
string str = "test";
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] arr = encoding.GetBytes(str);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("url");
request.Method = "PUT";
request.ContentType = "text/plain";
request.ContentLength = arr.Length;
request.KeepAlive = true;
Stream dataStream = request.GetRequestStream();
dataStream.Write(arr, 0, arr.Length);
dataStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string returnString = response.StatusCode.ToString();
}
catch
{}
__________________ Krishnakumar.S Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily |
| |||
| thnx krishna, but I'm getting the response which is have html element from client page. They told that there will be a response replied as "OK". I'm not getting this response. ![]()
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
| |||
| Use the POST method buddy.... See my coding is below... Code: HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("url")
request.Method = "POST";
string parameter = "";
parameter += "test=test1&";
parameter += "testing=testing1&";
parameter += "demo=demo1";
byte[] byteArray = Encoding.UTF8.GetBytes(parameter);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (HttpStatusCode.OK == response.StatusCode)
{
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
responseFromServer = reader.ReadToEnd();
File.WriteAllText(filepath, responseFromServer);
response.Close();
}
__________________ thanx n regards jeyaprakash.c |
| |||
| Yes, Thank you buddy. Now I'm getting the response. But one thing I couldn't save my files in to network directory path. for ex. (D:\ in my web folder).
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Webservice and its uses | poornima | ASP and ASP.NET Programming | 7 | 03-20-2008 09:49 PM |
| ASP.net 2.0 Webservice and WCF | kingmaker | ASP and ASP.NET Programming | 1 | 10-11-2007 04:15 AM |
| Error in webservice | Sathish Kumar | C# Programming | 7 | 09-20-2007 04:55 AM |
| Webservice – Xml & Soap | Karpagarajan | XML and SOAP | 1 | 08-31-2007 11:45 PM |
| note on webservice | nssukumar | Java Programming | 1 | 03-12-2007 05:05 AM |