IT Community - Software Programming, Web Development and Technical Support

HTTPWebRequest in webservice

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? ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 09-21-2007, 08:36 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Question HTTPWebRequest in webservice

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!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-22-2007, 05:11 AM
krishnakumar krishnakumar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 206
krishnakumar is on a distinguished road
Red face Re: HTTPWebRequest in webservice

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-25-2007, 04:30 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Smile Re: HTTPWebRequest in webservice

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!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-26-2007, 12:29 AM
jeyaprakash.c jeyaprakash.c is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 228
jeyaprakash.c is on a distinguished road
Red face Re: HTTPWebRequest in webservice

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-26-2007, 12:40 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Exclamation Re: HTTPWebRequest in webservice

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!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -7. The time now is 02:48 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0