End-of-file command in JSON HTTP POST request from putty - json

It is merely a childish question, but I have stuck upon an HTTP POST request through putty command line. After performing the initial request:
~$ POST <url:port/directory>
Please enter content (application/x-www-form-urlencoded) to be POSTed:
...(content posted there)
I have no option to send the command, since the only keyboard sequence working is CTRL-Z, which stops the procedure, other than sending the command. Is there any other interaction for the END-OF-FILE?

CTRL-D will simulate EOF. You can also pipe into POST, which may make things easier for testing, for example:
cat ~/my-json-file.json | POST <url:port/directory>

Related

Curl Post or Node/Express server converting double quotes to single quotes

I am sending a POST request from curl like this:
curl -H 'Content-Type:application/json" -X POST -d '{"key":"value"}' http://localhost:3000/parsejson
However, I am getting on my Node/Express server:
{'key':'value'} // req.body
So it is unclear to me if it is the curl request or the configuration of my node server. On my node server, I'm using: bodyParser.json() and bodyParser.urlencoded()
Thank you!
First of all this line is incorrect and you cannot run curl with that:
curl -H 'Content-Type:application/json" -X POST -d '{"key":"value"}' http://localhost:3000/parsejson
I'm mentioning it because this is a question about single and double quotes and you have single and double quotes messed up in your example of how you make a request, resulting in a code that cannot possibly be executed. Since this is obviously not how you really make the request, it is not clear how you do.
Now, if you want to see what you really get in the request, then don't use a body parser (temporarily switch it off, remove or comment it out) and run req.pipe(process.stdout) to display the request body on the server. Then you will know what you are getting from the client.
Also run curl with the -v option to see what it is actually sending.
If it turns out that curl is sending a correct JSON and your server gets a correct JSON in the request body then your problem must be somewhere else than in topics that you are asking about in this question.
Of course it's impossible to tell you what is the problem in that case because you didn't include even a single line of code in your question.

AWS IoT JSON Error

I'm trying to get a Skywire LTE Cat 1 modem (http://nimbelink.com/skywire-4g-lte-cat-1/) to update a thing shadow on AWS IoT. I have the device talking to AWS via HTTP, and am able to execute a GET command per their tutorial.
Now I am trying to execute a POST command to update my thing's shadow. However, whenever I try to send my POST command:
POST /things/AWS_Test_Thing/shadow HTTP/1.1
BODY: {"state":{"reported":{"Temp":55}}}
AWS sends me the following error:
HTTP/1.1 Bad Request
{"message":"Payload contains invalid json","traceId":"e53be1d6-7967f52c-4dd6-d7b95cc20628"}
I've never used JSON before, but from what I can gather,
{"state":{"reported":{"Temp":55}}}
should be valid JSON and complies with AWS IoT documentation (http://docs.aws.amazon.com/iot/latest/developerguide/thing-shadow-document-syntax.html#thing-shadow-example-request-json). What am I missing?
If you are updating the shadow via a POST request, you should have a "desired" statement instead of "reported".
Make sure you have the Content-Length header included as part of the request and signing procedure. The Content-Length must reflect the size of the JSON payload you are sending.

HTTP request error from running Postman Collection tests with Newman?

I've been using the new commandline for Postman, Newman, and have been attempting to run Collection tests that work fine when I pass them through the packaged app Jetpacks add-on, but do not run properly in the commandline. Although the json Collection file that I am passing does contain the proper header declarations, I don't have any other clues at this point, so I suspect that this may be an HTTP header issue. But I am not sure exactly what is wrong, as I am rather new to using Postman.
The tests that I'm trying to run are on some calls to an ASP.Net web API, very simple server response-checking one-line javascript tests like the ones in this tutorial.
A sample line that I enter into the console:
$ newman -c collectionfile.json -e environmentfile.json -n 5
achieves such a result:
RequestError: [token] terminated. Error: undefined
Any suggestions/help would be appreciated.
I ran into this problem as well and spent quite a few hours trying to figure it out. Eventually I realized that an address such as "www.google.com" will work in the chrome plugin UI, but not in Newman. For it to work in Newman, the address must be "https://www.google.com". Also, make sure that you have your data file (if you are using variables like {{url}}) set up correctly. You can use "-d dataFile.json" to define a data file. More information on that here.

How to hit a web page programmatically and silently?

I would like to know how can I hit a web page programmatically and silently using C/C++?
I tried ShellExecute (shellapi.h), don't know how to make use of it?
Use the HTTP protocol directly
netcat
curl
wget
HTTP Client Services
On linuxen there are perl implemented CLI commands (GET, PUT, POST), in short: pick one from a vast array; you platform will have tools too.
Simplistic example:
type request.http | netcat mywebserver:80
Where request.http could be as simple as
GET /
(mind the trailing empty lines, which SO helpfully hides)

Can Mercurial print command success messages instead of no response?

Can Mercurial print command success messages instead of no response in the output prompt?
It returns a value, hence you can wrap it around a script.
you could writepost-<command>hooks to output whatever you want on succesful commands. I don't see what the benefit would be however.
the book has a tutorial on hooks doing almost exactly what you want but with commit
. note with a post-command hook you shouldn't need to check the result for success as the hook will only be run if the command was successful.