postman 可以跑通 http://cms.pactera.com:9097/upload/public/32/Other/1013100210-575550.png ,但是代码不会写肿么办,postman 生成的代码是这样的
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"); RequestBody body = RequestBody.create(mediaType, "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name="Domain"\r\n\r\nxsh\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name="IsPublic"\r\n\r\ntrue\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name="FileType"\r\n\r\nImage\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name="FileCategory"\r\n\r\nOther\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name="files"; filename="C:\Users\z1557\Pictures\aa.png"\r\nContent-Type: image/png\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"); Request request = new Request.Builder() .url("http://cms.pactera.com:9097/api/services/app/Public/UploadFiles") .post(body) .addHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW") .addHeader("Content-Type", "application/x-www-form-urlencoded") .addHeader("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjMyIiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvbmFtZSI6IjE1NTcyMzg5MDIxIiwiQXNwTmV0LklkZW50aXR5LlNlY3VyaXR5U3RhbXAiOiI4NWQ4MjhkYS03Y2FjLTQ4NTItOWZmYS0zZTQxMjE5YTJjZWIiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJBZG1pbiIsInN1YiI6IjMyIiwianRpIjoiMmVkMDEyZTctNmM3My00ZDc0LWE4ZWYtOTIyNzk0YjY3OGUyIiwiaWF0IjoxNTM5Mzk2MjAwLCJuYmYiOjE1MzkzOTYyMDAsImV4cCI6MTUzOTQ4MjYwMCwiaXNzIjoiVmFua2UiLCJhdWQiOiJWYW5rZSJ9.FFbs7JH0Fad1yY5On-ivZCDb8UO-yZ0SE-HMqYFgRjk") .addHeader("Cache-Control", "no-cache") .addHeader("Postman-Token", "c3d0193f-0e32-4c4e-9154-bec83f7d6a62") .build();
Response response = client.newCall(request).execute();
postman 的参数在这 Domain:xsh IsPublic:true FileType:Image FileCategory:Other
BearerToken:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjMyIiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvbmFtZSI6IjE1NTcyMzg5MDIxIiwiQXNwTmV0LklkZW50aXR5LlNlY3VyaXR5U3RhbXAiOiI4NWQ4MjhkYS03Y2FjLTQ4NTItOWZmYS0zZTQxMjE5YTJjZWIiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJBZG1pbiIsInN1YiI6IjMyIiwianRpIjoiMmVkMDEyZTctNmM3My00ZDc0LWE4ZWYtOTIyNzk0YjY3OGUyIiwiaWF0IjoxNTM5Mzk2MjAwLCJuYmYiOjE1MzkzOTYyMDAsImV4cCI6MTUzOTQ4MjYwMCwiaXNzIjoiVmFua2UiLCJhdWQiOiJWYW5rZSJ9.FFbs7JH0Fad1yY5On-ivZCDb8UO-yZ0SE-HMqYFgRjk
1
Yohann97 OP 大佬们能帮帮我不,好几天了,写不出来,难受
|
2
secaas 2018-10-13 11:13:41 +08:00
这是个盗版头像= =
|
4
ghos 2018-10-13 15:27:02 +08:00
|
5
aLazarus 2018-10-13 16:09:30 +08:00 via Android
十一节前写了个使用 formdata 传图片和参数给接口的方法,不知道是不是你这意思?
|
6
dbolo123 2018-10-13 20:34:02 +08:00
postman 好像可以生成 okhttp 的代码吧?参考下?
|
7
lifespy 2018-10-14 11:25:57 +08:00
这个很简单啊,就行楼上说的,你可以用 okhttp,也可以用自带的
|
8
mmdsun 2018-10-14 11:50:17 +08:00 via Android
搜索 okhttp 上传文件就 OK 了。
|
12
Yohann97 OP 还是不行😭😭😭有大佬能在线指导下我么,好崩溃呀
|
13
Alexliu 2018-10-15 09:51:23 +08:00
不能直接前端直传么,还到后端倒手一次
|