成功時のキャプチャをhttpで取得。Axisのtcpmonを使った。
POST /api/v1/media HTTP/1.1 Host: 適当なアパッチホスト名:ポート番号 User-Agent: python-requests/2.13.0 Accept: */* Connection: keep-alive Accept-Encoding: gzip, deflate Authorization: Bearer アクセスキー Content-Length: 47436 Content-Type: multipart/form-data; boundary=d81c11d8d8434ba0aae091f4078c5ae0 --d81c11d8d8434ba0aae091f4078c5ae0 Content-Disposition: form-data; name="file"; filename="mastodonpyupload_1492518567.9830065_3K59EZOH48.png" Content-Type: image/png 以下略
そしてJava版はhttps決め打ちなので無理だった。
あとマルチパートフォームのHTTPについては http://d.hatena.ne.jp/satox/20110726/1311665904 に詳しい記載が。
HTTPClient4でのマルチパートについては http://www.baeldung.com/httpclient-multipart-upload にサンプルが。
HttpPost post = new HttpPost("http://echo.200please.com"); // ちなみにここは詐欺サイトなので注意 InputStream inputStream = new FileInputStream(zipFileName); File file = new File(imageFileName); String message = "This is a multipart post"; MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); builder.addBinaryBody ("upfile", file, ContentType.DEFAULT_BINARY, imageFileName); builder.addBinaryBody ("upstream", inputStream, ContentType.create("application/zip"), zipFileName); builder.addTextBody("text", message, ContentType.TEXT_PLAIN); // HttpEntity entity = builder.build(); post.setEntity(entity); HttpResponse response = client.execute(post);
という訳で、やっとJavaでアップロード成功。何だったんだ。
https://img.pawoo.net/media_attachments/files/000/155/370/original/ab37a3d25e7419e7.jpg?1492529929
コメント