我试图向一个网络服务机构发送图像文件。
我的守则如下:
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);
一种星体表示,图像档案已输入该方法。
服务签署:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Send(string imgData)
{}
任何关于如何发出这种看法的想法?
Thanks so much, Dan