CharlesのFAQにある通り、iPhoneにSSL証明ををインストールする必要があります。iPhoneのSafariから http://charlesproxy.com/charles.crt にアクセスし、SSL証明書をインストールしてください。
2015/06/24
2015/04/25
Http Boundary
コンテントタイプに以下を指定します。
FireFoxで転送してみた内容を見てみると「---------------------------102852708831426」というように「-」27文字と数字15文字で構成されており、ランダムの数字が付いていました。
\r\nは改行文字を示します。
IOSは
Boundary+5BA6C7D5E1A37EBE
Boundary+5BA6C7D5E1A37EBE
Boundary+5A402217BB55E461
Boundary+0A6551C579D31296
風、、、
headers.add(new BasicHeader("Content-type", multipart/form-data; boundary=Boundary+0A6551C579D31296
));
MultipartEntityBuilder.setBoundary("");
Content-Type: multipart/form-data; boundary=「バウンダリ文字列」\r\nバウンダリ文字列とは、複数の情報を続けて送る際の情報同士の「仕切線」の役目を果たします。この文字を調べて「仕切線」と判断するため、情報そのものにバウンダリ文字列が入っていてはいけません。
FireFoxで転送してみた内容を見てみると「---------------------------102852708831426」というように「-」27文字と数字15文字で構成されており、ランダムの数字が付いていました。
\r\nは改行文字を示します。
IOSは
Boundary+5BA6C7D5E1A37EBE
Boundary+5BA6C7D5E1A37EBE
Boundary+5A402217BB55E461
Boundary+0A6551C579D31296
風、、、
headers.add(new BasicHeader("Content-type", multipart/form-data; boundary=Boundary+0A6551C579D31296
));
MultipartEntityBuilder.setBoundary("");
MultipartEntityBuilder and Charset
日本語化けになっている。。
entity.addTextBody("plain_text", plain_text);
will use the default ContentType.TEXT_PLAIN which look like this...public static final ContentType TEXT_PLAIN = ContentType.create("text/plain", Consts.ISO_8859_1);
while ContentType.APPLICATION_JSON is using UTF-8 as below
public static final ContentType APPLICATION_JSON = ContentType.create("application/json", Consts.UTF_8);
So what i did was create our own ContentType like this..
entity.addTextBody("plain_text", plain_text, ContentType.create("text/plain", MIME.UTF8_CHARSET));
MultipartEntityBuilder: Omit Content-Type and Content-Transfer
What I want (what my chrome browser does):
2) There is a browser compatibility mode in HttpComponents that is used like this:
POST .../some.jsp HTTP/1.1
Host: ...
Connection: keep-alive
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary6tcnkxC7txvqE5Xl
------WebKitFormBoundary6tcnkxC7txvqE5Xl
Content-Disposition: form-data; name="merkmal"
5
What I get from MultipartEntityBuilderPOST.../some.jsp HTTP/1.1
Host: ...
Content-Type: multipart/form-data; boundary=m9Zb2QD-QaH-j-HqgGQfI8KwDkToz17ULYkZ
--m9Zb2QD-QaH-j-HqgGQfI8KwDkToz17ULYkZ
Content-Disposition: form-data; name="merkmal"
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
===>
lright - intense googeling finally produced an answer.
1) There are apparently some servers that do not get on well with the "Content-Transfer-Encoding" header. 2) There is a browser compatibility mode in HttpComponents that is used like this:
MultipartEntityBuilder uploadEntityBuilder = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE);2015/04/19
MIME Content-Type 表
MIME Content-Type 表
テキスト/ドキュメント
| 説明 | 拡張子 | MIME Content-Type |
|---|---|---|
| HTML(Hyper Text Markup Language) | html, htm | text/html |
| LaTeX | tex, latex, ltx | application/x-latex |
| PDF(Portable Document Format) | application/pdf | |
| Postscript | ps | application/postscript |
| Rich Text Format | rtf | application/rtf |
| SGML(Standard Generalized Markup Language) | sgm, sgml | text/sgml |
| TSV/タブ区切り形式 | tab, tsv | text/tab-separated-values |
| TeX | tex | application/x-tex |
| Text ファイル | txt | text/plain |
| XML(eXtended Markup Language) | xml | text/xml |
圧縮
| 説明 | 拡張子 | MIME Content-Type |
|---|---|---|
| JAR(Java Archiver) | jar | application/java-archiver |
| Compact Pro | cpt | application/mac-compactpro |
| GZIP(GNU ZIP) | gz | application/gzip application/x-gzip |
| BinHex(テキストエンコード;Macintosh) | hqx | application/mac-binhex40 |
| shar(Shell Archiver) | sh, shar | application/x-sh application/x-shar |
| sit(StuffIt) | sit | application/x-stuffit |
| tar(Tape Archiver) | tar | application/x-tar |
| Compress | z | application/x-compress |
| ZIP(Zigzag In line Package) | zip | application/zip application/x-zip-compressed |
イメージ
| 説明 | 拡張子 | MIME Content-Type |
|---|---|---|
| Illustrator | ai | application/postscript |
| BMP/Windows Bitmap | bmp, rle, dib | image/x-bmp image/x-ms-bmp |
| CGM(Computer Graphics Metafile) | cgm | image/cgm |
| AutoCAD DWF(Drawing Web Format) | dwf | drawing/x-dwf |
| EPS(Encapsulated Postscript Format) | epsf, eps, ps | appilcation/postscript |
| FIF(Fractal Image Format) | fif | image/fif |
| FlashPix | fpx | image/fpx image/x-fpx |
| GIF(Graphics Interchange Format) | gif | image/gif |
| JPEG(Joint Photographics Experts Group) | jpg, jpeg, jpe, jfif, jfi | image/jpeg |
| Kodak PhotoCD | pcd | image/pcd image/x-photo-cd |
| PICT(QuickDraw Picture) | pict, pct | image/pict |
| PNG(Portable Network Graphics) | png | image/x-png image/png |
| TGA(Targa)、VDA(Video Display Adapter) | tga, tpic, vda, vst | image/x-targa |
| TIFF(Tag Image File Format) | tiff, tif | image/tiff image/x-tiff |
| VRML | wrl | model/vrml x-world/x-vrml |
| xbm(X Bitmap format) | xbm | image/x-bitmap |
| xpm(X Pixmap) | xpm | image/x-xpixmap |
サウンド
| 説明 | 拡張子 | MIME Content-Type |
|---|---|---|
| AIFF(Audio Interchange File Format) | aiff, aif | audio/aiff audio/x-aiff |
| au(Audio File) | au | audio/basic |
| MIDI カラオケ | kar | audio/midi audio/x-midi |
| MPEG 1 Audio Stream | m1a | audio/mpeg audio/x-mpeg |
| MPEG 2 Audio Stream | m2a | audio/mpeg audio/x-mpeg |
| MIDI | midi, mid, smf | audio/midi audio/x-midi |
| MPEG 1 Layer 2 Audio Stream | mp2 | audio/mpeg audio/x-mpeg |
| MPEG 1 Layer 3 Audio Stream | mp3 | audio/mpeg audio/x-mpeg |
| MPEG Audio Stream | mpa, mpega | audio/mpeg audio/x-mpeg |
| Real Audio | rpm | audio/x-pn-realaudio-plugin |
| Next SND | snd | audio/basic |
| Shockwave Audio | swa | application/x-director |
| Twin VQ | vqf | audio/x-twinvq |
| WAVE | wav | audio/wav audio/x-wav |
動画
| 説明 | 拡張子 | MIME Content-Type |
|---|---|---|
| Shockwave for Authorware | aab | application/x-authorware-bin |
| Shockwave for Authorware | aam | application/x-authorware-map |
| Shockwave for Authorware | aas | application/x-authorware-seg |
| Advanced Streaming Format | asf | video/x-ms-asf |
| AVI | avi | vide/x-msvideo |
| Shockwave for Director | dcr, dir, dxr | application/x-director |
| Autodesk Animator | flc, fli | video/flc |
| MNG(Multiple Network Graphics) | mng | video/mng video/x-mng |
| MPEG 1 System Stream | m1s | vide/mpeg video/x-mpeg |
| MPEG 1 Video Stream | m1v | vide/mpeg video/x-mpeg |
| MPEG 2 System Stream | m2s | vide/mpeg video/x-mpeg |
| MPEG 2 Video Stream | m2v | vide/mpeg video/x-mpeg |
| Apple QuickTime Movie | moov, mov, qt | video/quicktime |
| MPEG Video/Audio/System | mpeg, mpg, mpe, mpv | vide/mpeg video/x-mpeg |
| Power Point | ppt | application/mspowerpoint application/ppt |
| RealMedia | rm | audio/x-pn-realaudio |
| Flash 1 & Future Splash Animator | spl | application/futuresplash |
| Flash 2 | swf | application/x-shockwave-flash |
| VDOLive | vdo | video/vdo |
| VivoActive | viv, vivo | video/vnd.vivo |
| StreamWorks | xdm, xdma | application/x-xdma |
その他
| 説明 | 拡張子 | MIME Content-Type |
|---|---|---|
| Channel Definition format | cdf | application/x-netcdf |
| Java クラスファイル | class | application/octet-stream |
| Windows 実行ファイル | exe | application/exe application/octet-stream |
| Perl スクリプト | pl | application/x-perl |
| RealAudio Meta File | ram | audio/x-pn-realaudio |
| Active X Document | vdb | application/activexdocument |
| TwinVQ | vqe, vql | audio/x-twinvq-plugin audio/x-twinvq |
2015/04/07
htmlClient EntityUtils.consume?? why
try {
//... some code
HttpEntity httpEntity = httpResponse.getEntity();
BufferedReader br = new BufferedReader(new InputStreamReader(http.Entity.getContent()));
String line;
while ((line = br.readLine())!= null) {
System.out.println(line);
}
EntityUtils.consume(httpEntity);
} catch (Exception e) {
//code
} finally {
httpClient.getConnectionManager().shutdown();
}
What EntityUtils.consume will do is release all resources held by the httpEntity,
which essentially implies releasing any underlying Stream and giving
the Connection object back to its pool (in the case your connection
manager is a multithreaded one) or freeing the connection manager so
that it can process the next request.
何かメモリを開放するみたいね
2015/04/05
java ssl charles
httpClientからhttpsを接続する時、firefox/iosのように証明書が必要....
$JAVA_HOME/jre/lib/security/cacerts, where JAVA_HOME is your java home directory for the JVM you’re using.
keytool -import -alias charles -file charles-proxy-ssl-proxying-certificate.crt -keystore JAVA_HOME/jre/lib/security/cacerts -storepass changeit
(changeit is the default password on the cacerts file)
Then try: keytool -list -keystore JAVA_HOME/jre/lib/security/cacerts -storepass changeit
$JAVA_HOME/jre/lib/security/cacerts, where JAVA_HOME is your java home directory for the JVM you’re using.
keytool -import -alias charles -file charles-proxy-ssl-proxying-certificate.crt -keystore JAVA_HOME/jre/lib/security/cacerts -storepass changeit
(changeit is the default password on the cacerts file)
Then try: keytool -list -keystore JAVA_HOME/jre/lib/security/cacerts -storepass changeit