JSON requests in C using libcurl

前端 未结 7 914
孤独总比滥情好
孤独总比滥情好 2020-12-08 12:04

I\'m defining a PUT request with a JSON request body using libcurl in C.

This how I\'m doing it:

    sprintf(jsonObj, \"\\\"name\\\" : \\\"%s\\\", \\         


        
7条回答
  •  孤城傲影
    2020-12-08 12:41

    A key part of understanding whether the system is behaving correctly is seeing what the program is actually sending over the network. So another way to check the byte stream, instead of pointing it at your server (and/or running Wireshark), is to just run a netcat instance in a separate window on the test machine:

    nc -l 8080
    

    and point the code (CURLOPT_URL) at "http://localhost:8080".

    You'll need to hit Control-D in the nc window to terminate the connection so that curl completes, but you can also type a test return text beforehand, which can be useful if you're expecting some sort of reply to test against.

提交回复
热议问题