【发布时间】:2015-08-28 09:17:51
【问题描述】:
我必须在 Android 中复制 thia curl 命令:
curl -X POST -F gps_track=@ANTON_MORODER.igc https://myserver -H "api-name:name" -H "api-key:key" -H "user-key:user" -H "Content-类型:应用程序/json"
我绑定了几种方法,但总是从服务器获得 400:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(doarama_api_url+"/activity");
httppost.setHeader("api-name",api_name);
httppost.setHeader("api-key",api_key);
httppost.setHeader("user-key", AppSettings.getdoaramatUserKey() );
httppost.setHeader("Accept", "application/json");
InputStreamEntity reqEntity = new InputStreamEntity(new FileInputStream(inIGC), -1);
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(true); // Send in multiple parts if needed
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
Log.d("DOARAMA", "statusCode: " + String.valueOf(statusCode));
谢谢
【问题讨论】:
-
您是否在清单中添加了互联网权限?
-
那是什么意思,400?你从哪里得到的?
-
I have to replicate thia curl comand。你忘了解释这个 curl 命令在做什么。该命令中的“文件”在哪里? -
对不起..文件在:文件 gpx_or_igcFolder = new File(Environment.getExternalStorageDirectory(), "TTLiveTrack24"); String inIGC = gpx_or_igcFolder.getPath()+ "/" + 文件名 + ".igc";
-
400 ???这是什么意思!!!!我问那个 CURL 命令中的文件在哪里。并解释你的 curl 命令。你是认真的吗?