Programing

PostMan에서 특정 CURL 시뮬레이션

lottogame 2020. 8. 18. 08:08
반응형

PostMan에서 특정 CURL 시뮬레이션


Postman을 사용하여 API 서버에 대한 일부 Curl 요청을 테스트하고 있습니다. API 개발자가 curl 명령을 제공했지만 Postman에서 보낼 수 없습니다. Postman에서 그러한 요청을하는 방법은 무엇입니까?

curl -X POST "https://api-server.com/API/index.php/member/signin" -d "{"description":"","phone":"","lastname":"","app_version":"2.6.2","firstname":"","password":"my_pass","city":"","apikey":"213","lang":"fr","platform":"1","email":"email@example.com","pseudo":"example"}"

--0xKhTmLbOuNdArY
Content-Disposition: form-data; name="userfile"; filename="profil.jpg"
Content-Type: image/jpeg
Content-Transfer-Encoding: binary

<ffd8ffe0 00104a46 49460001 01010048 ... a00fffd9>

—0xKhTmLbOuNdArY—

더 간단한 접근 방식은 다음과 같습니다.

  1. POSTMAN 열기
  2. 왼쪽 상단의 "가져 오기"탭을 클릭합니다.
  3. 원시 텍스트 옵션을 선택하고 cURL 명령을 붙여 넣으십시오.
  4. 가져 오기를 누르면 Postman 빌더에 명령이 있습니다!

도움이 되었기를 바랍니다!


In addition to the answer
1. Open POSTMAN
2. Click on "import" tab on the upper left side.
3. Select the Raw Text option and paste your cURL command.
4. Hit import and you will have the command in your Postman builder!
5. If -u admin:admin are not imported, just go to the Authorization 
   tab, select Basic Auth -> enter the user name eg admin and password eg admin.
This will automatically generate Authorization header based on Base64 encoder

1) https://api-server.com/API/index.php/member/signinURL 입력 상자에 입력 POST하고 드롭 다운에서 선택

2) 헤더 탭에 다음을 입력합니다.

콘텐츠 유형 : 이미지 / jpeg

콘텐츠 전송 인코딩 : 바이너리

3) 본문 탭에서 raw라디오 버튼을 선택 하고 다음을 작성하십시오.

{"description":"","phone":"","lastname":"","app_version":"2.6.2","firstname":"","password":"my_pass","city":"","apikey":"213","lang":"fr","platform":"1","email":"email@example.com","pseudo":"example"}

form-data라디오 버튼을 선택 하고 작성하십시오.

키 = 이름 값 = 사용자 Text파일 키 선택 = 파일 이름 Fileprofil.jpg 선택 및 업로드


Onkaar Singh이 언급 한 접근 방식을 시도했습니다.

  1. POSTMAN 열기
  2. 왼쪽 상단의 "가져 오기"탭을 클릭합니다.
  3. 원시 텍스트 옵션을 선택하고 cURL 명령을 붙여 넣으십시오.
  4. 가져 오기를 누르면 Postman 빌더에 명령이 있습니다!

그러나 문제는 인증이 필요한 Apis에서는 작동하지 않는다는 것입니다.

이것은 내 컬 요청이었습니다.

curl -v -H "Accept: application/json" -H "Content-type:
application/json" -X POST -d ' 
{"customer_id":"812122", "event":"add_to_cart", "email": "abc@def.com", }' 
-u 9f4d7f5445e7: https://api.myapp.com/api/event

본문을 가져온 후 올바르게 가져 오면 헤더와 URL도 가져 왔습니다. API 키 9f4d7f5445e7 만

-u 9f4d7f5445e7: https://api.myapp.com/api/v1/event 

컬 요청에서 가져 오지 못했습니다.

The way I solved it is, -u is basically used for Authorization. So while using it in Postman, you have to take the API key (which is 9f4d7f5445e7 in this case) and do Base64 Encode. Once encoded it will return the value OWY0ZDdmNTQ0NWU3. Then add a new header, the key name would be Authorization and key value would be Basic OWY0ZDdmNTQ0NWU3. After making that changes, the request worked for me.

There are online Base64 Encoders available, the one I used is http://www.url-encode-decode.com/base64-encode-decode/

Hope it helps!!!


sometimes whenever you copy cURL, it contains --compressed. Remove it while import->Paste Raw Text-->click on import. It will also solve the problem if you are getting the syntax error in postman while importing any cURL.

Generally, when people copy cURL from any proxy tools like Charles, it happens.

참고URL : https://stackoverflow.com/questions/27957943/simulate-a-specific-curl-in-postman

반응형