473,804 Members | 3,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using HttpWebRequest to send POST image data

4 New Member
Hello, I am trying to use HttpWebRequest to send some POST
data
I have accomplished this using:

HttpWebRequest req = (HttpWebRequest )
WebRequest.Crea te("http://mysite.com/index.php");
req.Method = "POST";
req.ContentType = "applicatio n/x-www-form-urlencoded";
string postData = "login=value1&p wd=value2&file= filename"
req.ContentLeng th = postData.Length ;

StreamWriter stOut = new
StreamWriter(re q.GetRequestStr eam(),
System.Text.Enc oding.ASCII);
stOut.Write(pos tData);
stOut.Close();

but i am getting response Upload problem but when i am uploading file using html Form-based File Upload then file is uploading it is showing upload success.
Sep 30 '08 #1
5 8852
Plater
7,872 Recognized Expert Expert
You set the content length before building all the content
Sep 30 '08 #2
kamlesh20J
4 New Member
hi i am uploading image by this method but i am getting upload problem response.plz anyone give me solution.

private void postImage()
{
HttpWebRequest request ;
request = (HttpWebRequest )HttpWebRequest .Create("url");




string strfileName = FileUpload1.Pos tedFile.FileNam e;


string strLogin = "login="+txtLog in.Text;
string strPassword = "&pass=" + txtPassword.Tex t;
string strFile1 = @"&file="+ strfileName;

string strRequestMessa ge = strLogin+strPas sword+strFile1;

request.Method = "POST";
request.Content Length = strRequestMessa ge.Length ;
request.Content Type = "applicatio n/x-www-form-urlencoded";

request.KeepAli ve = true;

//Create StreamWriter object
StreamWriter objStreamWriter = new StreamWriter(re quest.GetReques tStream());


objStreamWriter .Write(strReque stMessage);

objStreamWriter .Close();
//Get the response
System.Net.Http WebResponse objWebResponse = (HttpWebRespons e)request.GetRe sponse();
System.IO.Strea mReader objStreamReader = new System.IO.Strea mReader(objWebR esponse.GetResp onseStream());
string strResponse = objStreamReader .ReadToEnd().Tr im();
objStreamReader .Close();


}
Sep 30 '08 #3
Plater
7,872 Recognized Expert Expert
THREADS MERGED.
Please do not double post your questions. It is against the posting guidelines.

MODERATOR



Now then, Where exactly are you reading in the contents of the file you wish to upload and sending that? I do not see it in the code provided, it appears you do not do it at all.
Sep 30 '08 #4
kamlesh20J
4 New Member
i am sending name of the file in strFileName. Do i need to send byte array of the file
Sep 30 '08 #5
Plater
7,872 Recognized Expert Expert
Yes, that is how it works. You need do some kinda of content disposition heading too I think which could be tricky.
I recomend searching for a quick example on the web, there should be plenty.
Sep 30 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
40924
by: supster | last post by:
Hello, I am trying to use HttpWebRequest to simulate sending some POST data from a form to a PHP script. I have accomplished this using: HttpWebRequest req = (HttpWebRequest) WebRequest.Create("http://mysite.com/index.php"); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; string postData = "var=value1&var2=value2"
0
1397
by: khawar | last post by:
here is my code that i am using to send the post to verisign: using System.Drawing; using System.Data; using System.Data.SqlClient; using System.Data.OleDb; using System; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls;
3
6935
by: Patrick Fogarty | last post by:
I am programming what is to be a web service client that will use an HTTP-POST to request and retrieve data. The remote server (written in java for what it's worth) requires basic authentication as per RFC 2617 (http://www.faqs.org/rfcs/rfc2617.html). My attempts to authenticate are failing. The server requires the header to be present with the request. For security reasons, it will not reply in any way if the header is not present. ...
0
12800
by: barrybevel | last post by:
Hi, I'm trying to login to the www.vodafone.ie website using HttpWebRequest. It works fine with IE/Firefox and the .NET Web Control too, just not with my code. I think it's a redirect 302 problem. I'm using this code in a ASP.NET 2.0 application just in case that matters, maybe someone knows a better way to do this?
0
1532
by: sanjaygupta11 | last post by:
I am using httpwebrequest and httpwebresponse objects for sending data to remote appication by post and receiving the response from there. I am using this code in my windows application which will send a request to remote application. --------------------------------------------------------------------------------------------------------------- string lcUrl = "http://localhost/check/WebSite3/Default.aspx"; HttpWebRequest loHttp...
8
1665
by: ak | last post by:
Hi Guys, I was just wondering whether it is possible to translate JSP pages into ASP pages using XSLT. What I want is to be able to open a currently available website developed in JSP in a blackberry. Considering the limited real estate of blackberry, we would like to propose a translation of the websites using ASP .NET and XSLT by stripping out the HTML response from the JSP pages.
1
4417
by: WeCi2i | last post by:
Okay, I have a problem that has been stumping me for weeks. I have tried many different solutions and this is pretty much my last resort. I have seen a lot of good answers give here so I figured I would give it a try. First of all, I am using Visual Studio 2005 to write my program. I am using C# .NET as the language. I am running Windows XP Professional with all service packs and updates applied. Now, I have been trying to write a...
0
4116
by: shlim | last post by:
Currently I'm using VB.Net to perform a http/https multipart form post to a servlet. I'm able to perform the post using HttpWebrequest via GetRequestStream(). However, the servlet returned me with "The remote server returned an error: (500) Internal Server Error". Obviously, this means that I have not posted all the parameters as the servlet requested. But I just can't seem to find out what went wrong with my code. Hope someone can enlighten me,...
8
6103
by: inpuarg | last post by:
I 'm developing a c# (.net 2.0) windows forms application and in this application i want to connect to a java servlet page (HTTPS) (which is servlet 2.4 and which may be using Web Based SSO Sun Java System Access Manager but i 'm not sure), handle session management, get token, send data using post and get methods etc. I listened http traffic using Fiddler and sending the same messages from my application but browser based navigation is...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10076
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7616
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3816
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.