473,405 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Using HttpWebRequest to send POST image data

Hello, I am trying to use HttpWebRequest to send some POST
data
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 = "login=value1&pwd=value2&file=filename"
req.ContentLength = postData.Length;

StreamWriter stOut = new
StreamWriter(req.GetRequestStream(),
System.Text.Encoding.ASCII);
stOut.Write(postData);
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 8741
Plater
7,872 Expert 4TB
You set the content length before building all the content
Sep 30 '08 #2
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.PostedFile.FileName;


string strLogin = "login="+txtLogin.Text;
string strPassword = "&pass=" + txtPassword.Text;
string strFile1 = @"&file="+ strfileName;

string strRequestMessage = strLogin+strPassword+strFile1;

request.Method = "POST";
request.ContentLength = strRequestMessage.Length ;
request.ContentType = "application/x-www-form-urlencoded";

request.KeepAlive = true;

//Create StreamWriter object
StreamWriter objStreamWriter = new StreamWriter(request.GetRequestStream());


objStreamWriter.Write(strRequestMessage);

objStreamWriter.Close();
//Get the response
System.Net.HttpWebResponse objWebResponse = (HttpWebResponse)request.GetResponse();
System.IO.StreamReader objStreamReader = new System.IO.StreamReader(objWebResponse.GetResponseS tream());
string strResponse = objStreamReader.ReadToEnd().Trim();
objStreamReader.Close();


}
Sep 30 '08 #3
Plater
7,872 Expert 4TB
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
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 Expert 4TB
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
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)...
0
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;...
3
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...
0
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...
0
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...
8
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...
1
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...
0
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...
8
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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...

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.