I am using NSIS script for Rest API to send HTTP post with the JSON message body but unfortunately, I didn't find any solution.
Using of query string I can implement but I need to HTTP post request with JSON or as a raw message body.
inetc::post "" "sampleurl.php?username=$arg1&password=$arg2" "C:\output.txt" /END
With this query string we can request http post but I need HTTP post request with JSON or a raw message body.
I tried below command to send data to the sample url but $0 got "url parts error"
inetc::post ""{\"a\": \"a1\",\"b\": \"" + $username + "\",\"c\": \"" + $password + "\",\"d\": \"" + Windows + "\"}"" "http://sampleURL" "C:\output.log" /END
pop $4
MessageBox MB_OK|MB_ICONSTOP "perfect install $4"
inetc::post "" "sampleurl.php?username=$arg1&password=$arg2" "C:\output.log" /END
I expect output to request an HTTP post call with JSON or raw message body using nsis
Related
[I am trying to send parameter with GET request on RESTLET Netsuite !!
but i am continuously facing issue 403 forbidden when i am trying to concatenate parameter with URL , without parameter Request is working good and getting response but i want to send parameter so now i am trying to send parameter through Header but not able to read on server side !! please help me out .how to read request header values/parameters on Netsuite RESTLET.
1-first i tried concatenate with +"&name=asd" and then Uri builder throws error 403 forbidden
2-Now i am sending parameters through request.header.add("name":"asd") working good
This is my client side request code in which i am attaching parameters in request header
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.ContentType = "application/json";
request.Method = "GET";
request.Headers.Add(header);
request.Headers.Add("email", "polutry#key-stone.co");
request.Headers.Add("password", "123-4567");
WebResponse response = request.GetResponse();///here i got 403 on concatination ////
function getCustomer(context)
{
var request =https.request.headers;///headers function not defined
// var email =request.email;
//var password = request.password;
}
Want to get header values on server side][1]
[1]: https://i.stack.imgur.com/SEB68.png
In RESTlet you don't have access to request-headers, instead you get all the arguments passed to RESTlet in scriptContext(function argument to RESTlet entry point, get in current case).
Check this out on how to use RESTlet and how you can pass arguments.
Note: Add { "Content-Type": "application/json" } header since you want to pass data to RESTlet.
i'm running a gradle build with vertx web. my library dependecies include
// for mock API serving https://mvnrepository.com/artifact/io.vertx/vertx-core
compile group: 'io.vertx', name: 'vertx-core', version: '3.5.3'
compile group: 'io.vertx', name: 'vertx-web', version: '3.5.3'
so in my groovy script code i do this
Vertx vertx = Vertx.vertx()
HttpServer server = vertx.createHttpServer()
...
I then declare a route to catch all requests on resource and process the request and form a response - trying to keep it simple - just return simple string as response
Router allRouter = Router.router(vertx)
allRouter.route ( "/api/now/table/incident")
.handler(BodyHandler.create())
.blockingHandler { routingContext ->
def request = routingContext.request()
HttpMethod method = request.method()
def response = routingContext.response()
response.putHeader ("content-type", "text/plain")
def uri = routingContext.request().absoluteURI()
switch (method) {
case HttpMethod.GET:
println "processing a resource GET on uri : $uri "
response.end ("(GET) howdi will")
break
case HttpMethod.POST:
String bodyEnc = routingContext.getBodyAsJson().encodePrettily()
println "processing a resource POST on uri : $uri"
println "post request received post data : " + bodyEnc
response.end ("(POST) howdi will")
break
}
}
I create a handler for BodyHandling, before the general handler in the route.
Then I start the server with the route
server.requestHandler(allRouter.&accept)
server.listen(8081, "localhost")
works all fine for a get request from postman.
when i use a post request with a request body data - the service hangs and i have to cancel - it never gets to the switch statement. All that happens in the console when i issue the post is
23:30:16.455 [vert.x-eventloop-thread-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 32768
23:30:16.455 [vert.x-eventloop-thread-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2
23:30:16.455 [vert.x-eventloop-thread-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16
23:30:16.455 [vert.x-eventloop-thread-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8
23:30:16.478 [vert.x-eventloop-thread-1] DEBUG io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.bytebuf.checkAccessible: true
23:30:16.482 [vert.x-eventloop-thread-1] DEBUG io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector#51d486
This is the nearest to being a related topic enter link description here
I have tried this countless ways now, set bodyHandler inside the request when i get it etc - can't get it to work.
my postman post looks like this - where the headers are set to Content-Type application/json, Content-Length is 296 bytes (length of bytes in utf16), and Accept is text/plain to receive simple response
The documentation is just not clear. Blown 12 hours trying to crack this.
Does any one know exactly how one should get the post data on a request when using vertx web please
It appears as though my problem was the size of bytes being sent. I had calculated the bytes of the reqBody string as 296 bytes (using UTF16 charset), and set this into the Postman request.
So the vertx server was trying to read that many when processing the body and hanged. When I just did reqBody.getBytes().size - effectively UTF8, this returned 147 bytes. When I changed the content-length to this in postman, it started to work.
There is a timing issue in where you setup the BodyHandler. I tried this is tin the switch case, and it fails with request has already been read.
However neither of these seem to work successfully.
option 1 : ' create body handler before the route (path) call'
allRouter.route().handler(BodyHandler.create())
//now try and setup the route for API path interception
allRouter.route ( "/api/now/table/incident")
.blockingHandler { routingContext -> ...
option 2 : 'chain the handlers but put the Body Handler first'
//now try and setup the route for API path interception, followed by body handler
allRouter.route ( "/api/now/table/incident")
.handler(BodyHandler.create())
.blockingHandler { routingContext ->...
This was setting the content-length, assuming UTF16 for internal byte size that was the real problem. Now back to trying to complete what I set out to do.
When a user click a button I have to create an excel file (and this works perfect) but in the same time the user have to download the file that I've created before, but the download doesn't start...
Controller:
public function downloadAction() {
// I create the excel file .......
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$this->getResponse()->setRawHeader( "Content-Type: application/vnd.ms-excel; charset=UTF-8" )
->setRawHeader( "Content-Disposition: attachment; filename=excel.xls" )
->setRawHeader( "Content-Transfer-Encoding: binary" )
->setRawHeader( "Expires: 0" )
->setRawHeader( "Cache-Control: must-revalidate, post-check=0, pre-check=0" )
->setRawHeader( "Pragma: public" )
->setRawHeader( "Content-Length: " . filesize( $filename ) )
->sendResponse();
echo json_encode(array(
'success' => 'true',
'xls' => 'http://'.$_SERVER['SERVER_NAME'].'/export/excel.xls'
));
exit();
}
Same time is not possible, as the content of the file is passed inside the body of the response with Content-Disposition header.
Yóu need to create 2 seperated calls.
After the client recieves the JSON Response, the client need to call another uri, maybe the one you just delivered to get the content of the file.
On a website you need to add an iframe into the page, which has src="http://'.$_SERVER['SERVER_NAME'].'/export/excel.xls".
<iframe src="http://'.$_SERVER['SERVER_NAME'].'/export/excel.xls"></iframe>
This will start the download inside the current page, else the page would be changed an an empty window will be shown.
Maybe use Javascript to generate the html for the iframe or just add a hidden iframe with id="downloadContainer" and just change the src for this iframe.
Another idea would be, sending the JSON data as header together with the file as body.
X-status: success
X-filename: //server.com/export/test.xls
But both params are not needed, as you could use default transfer specific params for it.
Why not use HTTP StatusCode for success/error status.
200 -Ok
201 -Created
400 -Bad request
404 -Not found
405 -Not allowed
500 -Server error
Set the HTTP Response Code inside Controller Action like that:
$this->getResponse()->setHttpResponseCode(405);
And for filename use your Content disposition header.
To send the file content just do:
readfile($absolute_path_to_file);
exit(1);
I need to implement a HTTP server in node.js without using http module. How fun!
I'm having trouble with sending the response socket.
I'm trying to fetch a file and so my code looks as follows:
fileStream = fs.createReadStream('example.jpg');
fileStream.on("end", function (close) {
var str = "HTTP/1.1 200 OK\r\Content-Type: image/jpeg\r\n" //and some more headers.
socket.write(str);
socket.pipe(fileStream);
socket.end("\r\n");
});
What am I missing?
I am of course using net module to get the socket and fs as well.
There are two main issues with the code you have.
Responses as formatted as headers followed by two sets of "\r\n", and then the content. The "\r\n" in your end() call should be in str. You also are missing an 'n' from the first "\r\n".
You are trying to pipe the contents of the readstream, which is great, but you are doing all of this inside of the steam's end(), so the pipe as nothing left to send because the data was all already emitted.
Try something like this instead. Create the read stream, send the response and pipe then rest.
var str = "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\n\r\n";
socket.write(str);
var fileStream = fs.createReadStream('example.jpg');
fileStream.pipe(socket);
I'm starting to learn node.js. I'm following this tutorial and I've run into a problem where some POST data is received properly but when it's returned to the client, it becomes "undefined".
Here's the code for grabbing the POST data (this is Coffeescript btw):
postData = ""
request.setEncoding "utf8"
request.addListener "data", (postDataChunk) ->
postData += postDataChunk
console.log "Received POST data chunk '" + postDataChunk + "'."
request.addListener "end", ->
console.log "postData at end: " + postData
POST = qs.parse postData
console.log POST
route handle, pathname, response, POST.text
The POST text is sent to a routing function along with the response object. The code there is:
upload = (response, postData) ->
console.log "Request handler 'upload' was called"
console.log "post data in upload: " + postData
response.writeHead 200, "Content-Type": "text/plain"
response.end "You sent: " + postData
In the console output, PostData is set correctly but when I view the output in the browser it'll always say "You sent: undefined"
Can anyone help me understand what's going wrong?
You need to look at POST.text inside the end callback. Instead of console.log POST, do console.dir POST and see if the POST object has a property named text defined. My guess is it does not. If not, log the raw postData string and see if it is not what you expect.