Hi Everyone,
I'm trying to send an image file to a web service.
here's my code:
ConnectionFactory connFact = new ConnectionFactory();
ConnectionDescriptor connDesc;
//String value = new String(data);
String value= Base64OutputStream.encodeAsString(data, 0, data.length, false, false);
value = "imgData=" + value;
connDesc = connFact.getConnection("http://localhost:50806/Send");
int iResponseCode = 0;
HttpConnection httpConn = null;
OutputStream os = null;
if (connDesc != null)
{
try
{
byte[] theByteArray = value.getBytes();
httpConn = (HttpConnection)connDesc.getConnection();
httpConn.setRequestProperty("Content-Type", "image/jpeg");
httpConn.setRequestMethod(HttpConnection.POST);
httpConn.setRequestProperty("Content-Disposition", "form-data");
httpConn.setRequestProperty("Connection", "Keep-Alive");
httpConn.setRequestProperty("Content-Length", String.valueOf(data.length));
//os = httpConn.openOutputStream();
//os.write(theByteArray);
DataOutputStream printout = new DataOutputStream (httpConn.openOutputStream());
printout.write(theByteArray);
iResponseCode = httpConn.getResponseCode();
}
catch(Exception e){
e.printStackTrace();
}
finally{
if(os != null)
os.close();
if(httpConn != null){
httpConn.close();
}
}
}
return Integer.toString(iResponseCode);
A byte array represented the image file is passed into the method.
service signature:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Send(string imgData)
{}
Any ideas on how to send this?
Thanks so much, Dan