ProxymanApp / Proxyman

Modern. Native. Delightful Web Debugging Proxy for macOS, iOS, and Android ⚡️
https://proxyman.io
5.58k stars 187 forks source link

When uploading form data, "copy curl" does not get the body #898

Closed PangYenChen closed 3 years ago

PangYenChen commented 3 years ago

Proxyman version? (Ex. Proxyman 1.4.3)

2.25.0 (22500)

macOS Version? (Ex. mac 10.14)

10.15.6(19G2021)

Steps to reproduce

Upload an image using form data format, and Proxyman gui click "copy curl".

Expected behavior

Get the curl with form data format body.

NghiaTranUIT commented 3 years ago

Thanks for the bug report @PangYenChen. I'm able to reproduce the bug when uploading the file with multipart/form-data 👍

I'm going to fix it and send a BETA build this week 🌮

NghiaTranUIT commented 3 years ago

Hey @PangYenChen, there are two possible solutions:

cURL with the invalid body, but exact multipart/form-data

I tried to perform the "copy as a cURL" with Charles and Fiddler, and the result is:

curl -H 'Host: httpbin.org' -H 'user-agent: insomnia/2021.3.0' -H 'content-type: multipart/form-data; boundary=X-INSOMNIA-BOUNDARY' -H 'accept: */*' --data-binary "--X-INSOMNIA-BOUNDARY
Content-Disposition: form-data; name=\"file\"

proxyman.png
--X-INSOMNIA-BOUNDARY
Content-Disposition: form-data; name=\"body\"; filename=\"Screen Shot 2021-05-24 at 09.00.12.png\"
Content-Type: image/png

�PNG


IHDR� $9�PDiCCPICC Profile(�c``H,(�aa``��+)
rwR���R`��� ��� Π��\\��T��Q��k� ��.�,��\{'�x�!���Yɣݘ�QWJjq2���)�E%� @�ryI��d�d���!�5 v�}�&$�Ⱦd$g$��O�l�$$�t$6�^�|�<\�L� 8�TP�ZQ���*�2�3J�!��������`d`d��
o��ρ�pd;��_��`񕁁yB,i&��V�[1�����v� �(��o,�i�F6����?�10�Of`�;���ߋ����h��y�ao��`��eXIfMM*>F(�iN����x��� ASCIIScreenshot�6�   pHYs%%IR$��iTXtXML:com.adobe.xmp<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"XMP Core 6.0.0\">
   <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">
      <rdf:Description rdf:about=\"\"
            xmlns:exif=\"http://ns.adobe.com/exif/1.0/\">
         <exif:PixelYDimension>288</exif:PixelYDimension>
         <exif:PixelXDimension>640</exif:PixelXDimension>
         <exif:UserComment>Screenshot</exif:UserComment>
      </rdf:Description>
   </rdf:RDF>
</x:xmpmeta>
I�c�iDOT�(��ưq��IDATx�ܱ� C���؉�/���?t����Z�� @�d���ZP @��0 @ &`�
� `� @�@L��.. @�t @����+\\ @��x��?�� 0Ce�J���� 0c��K�0� @ &`�
� `� @�@L��.. @�t @����+\\ @��� @�10V�� @��
 @�b`�pq  @�� @���X�� @�@7@��   ����%@��n� 0c��K�0� @ &`�
� `� @�@L��.. @�t @����+\\ @��� @�10V�� @��
 @�b`�pq  @�� @���X�� @�@7@��   ����%@��n� 0c��K�0� @ &`�
� `� @�@L��.. @`�km @��ӵ� @��#`: @�@L��.. @�t @����+\\ @��� @�10V�� @��
 @�b`�pq  @�� @���X�� @�@7@��   ����%@��n� 0c��K�0� @ &`�
� `� @�@L��.. @�t @����+\\ @��� @�10V�� @��
 @�b`�pq  @�� @���X�� @�@7@��   ����%@��n� 0c��K�0� @ &`�
� `� @�@L��.. @�t @����+\\ @��� @�10V�� @������@� �0;]KJ�8�C @���X�� @�@7@��    ����%@��n� 0c��K�0� @ &`�
� `� @�@L��.. @�t @����+\\ @��� @�10V�� @��
 @�b`�pq  @�� @���X�� @�@7@��   ����%@��n� 0c��K�0� @ &`�
� `� @�@L��.. @�t @����+\\ @��� @�10V�� @��
 @�b`�pq  @�� @���X�� @�@7@��   ����%@��n� 0c��K��Z @�@G��t-) @��� 0c��K�0� @ &`�
� `� @�@L��.. @�t @����+\\ @��� @�10V�� @��
 @�b`�pq  @�� @���X�� @�>��G���IDAT�ֱ�@A\
$��q�̷q��r���{� @ #0`�kA  @�[�� @����+\\ @��� @�10V�� @�� @�b`�pq  @�� @���X�� @�@?@��   ����%@��~� 0c��K�0� @ &`�
� `� @�@L��.. @�� @����+\\ @��� @�10V�� @�� @�b`�pq   @��>��@� �0;]KJ���G @���X�� @�@?@�� ����%@��~� 0c��K�0� @ &`�
� `� @�@L��.. @�� @����+\\ @��� @�10V�� @�� @�b`�pq   @�� @���X�� @�@?@��   ����%@��~� 0c��K�0� @ &`�
� `� @�@L��.. @�� @����+\\ @��� @�10V�� @�� @�b`�pq   @�� @���X�� @�@?@��   ����%@��~� 0c��K��� @������ZR @��0= @ &`�
� `� @�@L��.. @�� @����+\\ @��� @�10V�� @�� @�b`�pq   @�� @���X�� @�@?@��   ����%@��~� 0c��K�0� @ &`�
� `� @�@L��.. @�� @����+\\ @��� @�10V�� @�� @�b`�pq   @�� @���X�� @�@?@��   ����%@��~� 0c��K�0� @ &`�
� `� @�@L��.. @�� @����+\\ @���Ϸ0 @�t�Nג @���� @�10V�� @�� @�b`�pq   @�� @���X�� @�@?@��   ����%@��~� 0c��K�0� @ &`�
� `� @�@L��.. @�� @����+\\ @��� @�10V�� @�� @�b`�pq   @�� @���X�� @�@?@��   ����%@��~� 0c��K�0� @ &`�
� `� @�@L��.. @�� @����+\\ @��� @�10V�� @�� @�b`�pq   @�� @���X�� @�~�:�&n��IEND�B`�
--X-INSOMNIA-BOUNDARY--
" 'https://httpbin.org/post?name=proxyman'

It's exactly the request body, but when executing it on the Terminal, it yields the error (Invalid body).

Better cURL with -F option

From cURL Doc, we can use -F to make a correct multipart/form-data request.

curl 'https://httpbin.org/post?name=proxyman' \
-X POST \
-H 'User-Agent: insomnia/2021.3.0' \
-H 'Host: httpbin.org' \
-H 'Content-Type: multipart/form-data; boundary=X-INSOMNIA-BOUNDARY' \
-H 'Accept: */*' \
-F 'file=proxyman.png' \
-F 'body=@image.png'

You can execute this cURL on the Terminal app. However, it appends the boundary=------------------------4b3032089740ba4f automatically.


Just wondering, what scenario do you need? @PangYenChen 🤔

  1. Just a body like Charles/Fiddler
  2. Or a working cURL for multipart/form-data
PangYenChen commented 3 years ago

I want to upload an image to the server from a mobile app.

I need to tell my backend colleague what request the mobile app sent.

In general, the image file is not a local file on my computer.

So, the exact multipart/form-data will be better.

I am not a native English speaker. Please pardon me.

NghiaTranUIT commented 3 years ago

Thanks for your clarification @PangYenChen 👍 I will follow this approach because it's easier to implement 😄

NghiaTranUIT commented 3 years ago

@PangYenChen please check out this Beta build: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.26.0_cURL_Multipart_Form_Data.dmg

It will fix your bug 👍

NghiaTranUIT commented 3 years ago

Meanwhile, I've implemented the multipart/form-data previewer at https://github.com/ProxymanApp/Proxyman/issues/833#issuecomment-847667322

Please check it out 😄 @PangYenChen

PangYenChen commented 3 years ago

Thanks a lot!

Though it works properly for my case, I think that generally “Better cURL with -F option” would be a better option for other people.

If there is a switch to toggle the result of “copy curl”, it would be perfect!

It’s just a suggestion.

Thanks again!

By the way, multipart/form-data previewer is amazing!