473,484 Members | 1,635 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with a sending of a image via HTTP

1 New Member
Hello everyone!! I'm trying to send a image (jpg) from a C# program to a CGI perl. The problem is that the code of the client C# is not working properly...I guess. The steps to send the image are: 1) I get the array of bytes from the image 2)Convert the array to string. 3) Send the string via http to the cgi in Perl. My question is, is this code working good? I don't know if the encode method is the correct. Please, Help me !
the real problem is the CGI doesn't receive the total number of bytes from the image but lower number, so I can save an image in the server but it can't be seen because is incomplete . I think the problem is in this method....

This is the method which I use to send the request and to receive the answer,

Expand|Select|Wrap|Line Numbers
  1. public String enviarImagen(String chorro)
  2.         {
  3.             String parametro = "imagen=" + chorro;
  4.             System.Net.HttpWebRequest cliente = (HttpWebRequest)WebRequest.Create("http://localhost/cgi-bin/subirImagen.pl");
  5.             cliente.Method = "POST";
  6.  
  7.             byte[] bytesparametros = Encoding.ASCII.GetBytes(parametro);
  8.             Stream os = null;
  9.             try
  10.             { // send the Post
  11.  
  12.                 cliente.ContentLength = bytesparametros.Length;   //Count bytes to send
  13.                 os = cliente.GetRequestStream();
  14.             //Send it
  15.                 os.Write(bytesparametros, 0, bytesparametros.Length);
  16.  
  17.             }
  18.             catch (WebException ex)
  19.             {
  20.                 MessageBox.Show(ex.Message, "HttpPost: Request error",
  21.                    MessageBoxButtons.OK, MessageBoxIcon.Error);
  22.             }
  23.             finally
  24.             {
  25.                 if (os != null)
  26.                 {
  27.                     os.Close();
  28.                 }
  29.             }
  30.  
  31.             try
  32.             {
  33.                 System.Net.WebResponse respuesta = cliente.GetResponse();
  34.                 StreamReader mensaje = new StreamReader(respuesta.GetResponseStream());
  35.                 String resultado = mensaje.ReadToEnd();
  36.                 mensaje.Close();
  37.                 return resultado;
  38.             }
  39.  
  40.             catch (WebException e)
  41.             {
  42.                 WebExceptionStatus status = e.Status;
  43.                 if (status == WebExceptionStatus.ProtocolError)
  44.                 {
  45.                     MessageBox.Show("The server returned protocol error ");
  46.                     // Get HttpWebResponse so that you can check the HTTP status code.
  47.                     HttpWebResponse httpResponse = (HttpWebResponse)e.Response;
  48.                     MessageBox.Show((int)httpResponse.StatusCode + " - "
  49.                        + httpResponse.StatusCode);
  50.                 }
  51.                 return e.Status.ToString();
  52.             }
  53.             catch (Exception ex)
  54.             {
  55.                 return ex.ToString();
  56.             }
  57.  
  58.         }
Mar 23 '07 #1
1 1641
kenobewan
4,871 Recognized Expert Specialist
Welcome to the site. Have you got your application working yet? I suggest that if you haven't, debug until you get one part working and then go from there.
Mar 26 '07 #2

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

Similar topics

1
1995
by: no one | last post by:
I have been searching various boards trying to figure out how to generate an image along with other html. I intend to put the image in a table, but for now I am just having problem getting the...
5
3317
by: john | last post by:
Here is the short story of what i'm trying to do. I have a 4 sided case labeling printer setting out on one of our production lines. Now then i have a vb.net application that sends data to this...
2
5619
by: VenuGopal | last post by:
Hi Everyone, in my application i am interacting to a known server. i send a request and get a response from the server. i am using XML and HTTP here. part of the job is that the XYZ server is...
2
2944
by: lucifer | last post by:
hi, i am creating an simple http server ie it serves only static pages . u can compile the code then use ur browser if it is IE then the it shows the page but the http header is also shown...
0
5518
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
4
12039
by: david | last post by:
hello, I have a client/server application. the server capture picture from webcam and send it to every client connected to it.the network part works good and the capture from webcam too. I...
5
2134
by: ibid | last post by:
hi every one just wondering if anyone could help sorry if i seem abit dumb but im a newbie to it all ive got to asign a mail program on my auction site in the config.pl files (i think this is the...
3
2197
by: FFMG | last post by:
Hi, I want to send expiry headers along with my images. This is the code in my .htaccess file Code: -------------------- ...
2
9767
by: ksheerasagar17 | last post by:
Hello All, Scenario: Sending an image through webservice as byte array to an Java webservice. The Problem1: The webservice method image property expects (data type) SByte rather than Byte...
0
6953
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
7105
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,...
1
6813
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
5407
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4845
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...
0
4529
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...
0
3046
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3041
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1359
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.