如何将图像上传到.net服务器并保存网址

时间:2011-10-11 06:15:50

标签: android .net sql-server file-upload

任何人都可以帮我上传图片,    我尝试了以下代码

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);
                    }

,服务器代码为:

<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>

我很久以来一直在努力.........

0 个答案:

没有答案