how to upload image to .net server and save url
can any one help me in uploading image, I tried the following code
try {
HttpClient client = new DefaultHttpClient();
String postURL = "http://imageupload.debtor.org/carimages.aspx";
HttpPost post = new HttpPost(postURL);
FileBody bin = new FileBody(file);
开发者_运维问答 MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("",new StringBody("__VIEWSTATE"));
reqEntity.addPart("",new StringBody("__EVENTVALIDATION"));
reqEntity.addPart("fupimage", bin); post.setEntity(reqEntity);
HttpResponse response = client.execute(post);
HttpEntity resEntity = response.getEntity(); BufferedReader reader1 = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
String sResponse;
StringBuilder s = new StringBuilder();
while ((sResponse = reader1.readLine()) != null) {
s = s.append(sResponse);
System.out.println(sResponse);
}
and the server code is:
<body>
<form method="post" action="carimages.aspx" id="form1" enctype="multipart/form-data">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTI3MTMxMTcxNw9kFgICAw8WAh4HZW5jdHlwZQUTbXVsdGlwYXJ0L2Zvcm0tZGF0YWRk0E+rBvXjvxJ/8Rc5RgEUFuspKFYNppSPcgnLFuy7+xw=" />
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgLkr/uNBALhmZP/ASc2KQDquqV9kJCRrr2nUtJwnv/bXCN0MyC1qpx/NJZt" />
<div>
<input type="file" name="fupimage" id="fupimage" />
<input type="submit" name="btnImageUpload" value="Upload" id="btnImageUpload" /> </div>
</form>
</body>
I hade been trying from a long time.........
精彩评论