将curl命令翻译成java / android

| 有人可以帮我弄清楚如何将以下curl命令转换为Java语法以用于Android应用程序吗? curl命令为: curl -u用户名:密码-H \“内容类型:application / vnd.org.snia.cdmi.container \” http:// localhost:8080 / user curl -u用户名:密码-T /home/user1/a.jpg -H \“ Content-Type:image \” http:// localhost:8080 / user / a.jpg 谢谢     
已邀请:
您可以在Android中使用Apache HttpClient执行HTTP发布。 HttpClient代码段(未经测试)
public void postData(String url) {
    // Create a new HttpClient and Post Header
   HttpClient httpclient = new DefaultHttpClient();
   HttpPost httppost = new HttpPost(url);

try {
    // Set the headers (your -H options)
    httpost.setHeader(\"Content-type\", \"application/json\");
    // Add your data
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
    nameValuePairs.add(new BasicNameValuePair(\"param1\", \"value1\"));
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

    // Execute HTTP Post Request
    HttpResponse response = httpclient.execute(httppost);

} catch (Exception e) {
    // Exception handling
} 
} 检查以下链接以获得基本身份验证部分(您的-u选项) http://dlinsin.blogspot.com/2009/08/http-basic-authentication-with-android.html 检查以下答案以上传文件(您的-T选项) 如何使用与PHP一起使用的Java HttpClient库上载文件     

要回复问题请先登录注册