Java android multipart / form-data

时间:2017-12-12 08:17:57

标签: java android soap

这是我对soapUI的请求,我想用andorid发送它。

POST http://10.8.0.16:8080/SC_TerminalAssist/proxy/photos/note HTTP/1.1
Accept-Encoding: gzip,deflate
Authorization: SCToken 3c205d0e-9415bd5d-5d72-42ab-b1ce-723eadd5d658
Content-Type: multipart/form-data; boundary="----=_Part_13_4273976.1513064436568"
MIME-Version: 1.0
Content-Length: 434
Host: 10.8.0.16:8080
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)


------=_Part_13_4273976.1513064436568
Content-Type: text/json; charset=Cp1250; name=login_param.json
Content-Transfer-Encoding: binary
Content-Disposition: form-data; name="metadata"; filename="login_param.json"

{
   "company": "elte gps",
   "user": "franek",
   "secure_password": "C4CA4238A0B923820DCC509A6F75849B",
   "secure_device_id": "C4CA4238A0B923820DCC509A6F75849B"
}
------=_Part_13_4273976.1513064436568--

我这样做了:

   JSONObject jsonObject = new JSONObject();
    SharedPreferences sp ;
    sp = getSharedPreferences("pfref", Activity.MODE_PRIVATE);
    String pass = sp.getString("pass", "");
    String firm = sp.getString("firm", "");
    String login = sp.getString("login", "");
    String boundary;
    boundary = "===" + System.currentTimeMillis() + "===";

    try {
        jsonObject.put("company", firm);
        jsonObject.put("user", login);
        jsonObject.put("secure_password", HashUtil.md5(pass));
        jsonObject.put("secure_device_id", HashUtil.md5(DeviceUtil.getDeviceId(PhotoActivity.this)));
    } catch (JSONException e) {
        e.printStackTrace();
    }

    ImageLoader imageLoader = ImageLoader.getInstance();

    FileEntity fileEntity = null;
    try {
        fileEntity = new FileEntity(file, "image/jpeg");
    } catch (Exception e) {
        e.printStackTrace();
    }

    RequestParams params = new RequestParams();
    BasicHeader[] headers = new BasicHeader[]{new BasicHeader("Authorization", "SCToken " + token)};
    // params.put("photos", fileEntity);
    params.put("metadata",jsonObject);

    client.post(PhotoActivity.this, RestClient.getAbsoluteUrl("photos/note"), headers, params, "multipart/form-data", new AsyncHttpResponseHandler() {

        @Override
        public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
            Log.d("sokces", "uploadFile response: " + statusCode);
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
            Log.d("sokces nie", "uploadFile ERROR! " + statusCode);
            Log.d("fail " , new String(responseBody));
        }
    });

但它没有用,我做错了但我不知道自己做错了什么。我把我在android中做的和我放入soapUI的样本请求。

0 个答案:

没有答案