Get http post request body in perl - json

Request header (from Firebug):
Accept application/json, text/plain, */*
Accept-Encoding gzip, deflate
Content-Type application/json;charset=utf-8
Request json:
{"key":"value"}
So how to get request body in perl?

What webserver?
Usually POST data is available by simply reading from STDIN.
If you are using the venerable CGI module (under mod_perl or not), you can get the body via:
$cgi->param('POSTDATA')
(if, as in this case, the content type isn't application/x-www-form-urlencoded or multipart/form-data)

Related

Multipart request without image file

I want to call multipart service without uploading an image file. It only has input JSON data.
Is it possible to call multipart service with only JSON & file is optional?
it's absolutely possible to make a valid Multipart/form-data request without any files in, yes.
here is a HTTP Post request with multipart/form-data containing only the variable "foo" with the value "bar":
POST / HTTP/1.1
Host: 127.0.0.1:9999
User-Agent: curl/7.59.0
Accept: */*
Content-Length: 141
Content-Type: multipart/form-data; boundary=------------------------c6d530a086d1167c
--------------------------c6d530a086d1167c
Content-Disposition: form-data; name="foo"
bar
--------------------------c6d530a086d1167c--
generated with the curl command
curl -F "foo=bar" http://127.0.0.1:9999

XMLHttpRequest Header : Decode Binary Data Upon Server Arrival

I am building a multipart/form-data httprequest, using Javascript's XMLHttpRequest object. Here are the headers:
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.5
Content-Length: 38539
Content-Type: multipart/form-data; charset=UTF-8; boundary=CONTENT_BOUNDARY
Cookie: __utma=111872281.167592067.1396133699.1396133699.1396133699.1; PHPSESSID=ea7cfjgi8e29v1bhnrj580vbc2
DNT: 1
Host: localhost:90
Referer: localhost:90/my_secret_referer/no_peeking.php
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0
I send the request to a PHP document.
In the following snippet one can observe a part of the request body. It details the transmission of binary data in base64 representing an image file that has been selected.
--CONTENT_BOUNDARY
Content-Disposition: form-data; name="images[]"; filename="airplane.jpg"
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
.../9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDABkRExYTEBkWFBYcGxkeJT4pJSIiJUw3Oi0...
This body part cooperates with the entire request to create a successful AJAX request to my server. When the information arrives at the server, I decode the information and do what I may with it.
The segment of this process that I am unsatisfied with is the manual decoding of the binary data. One is always able to receive uploaded images in the server as complete, legible image files when using jQuery's $.ajax() or Malsup's jQuery Form. I have looked into the format of the two mentioned requests and have found that they too send binary information using a multipart/form-data request. The one difference that I have found which I have not intentionally made is that my request is furnished with a
charset: utf8;
specification inside of the Content-Type after I send it.
Can I, and if I can, how can I tell the server to decode the binary information it receives?

YouTrack API Form Data Description

I am trying to send the description in form data to create an issue but it seems it is only possible through parameters with a length restriction. Does anybody know a way around this or am I doing something wrong?
PUT /rest/issue?project=LSDebug&summary=Debug%2520Log HTTP/1.1
Connection: keep-alive
Content-Length: 266
Accept: application/json, text/plain, */*
Origin: http://localhost:8080
Content-Type: application/x-www-form-urlencoded
Referer: http://localhost:8080/index.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Query String Parameters
project:LSDebug
summary:Debug%20Log
Form Data
description=Submitted%20Form%20name%3A%20null%2C%20Id%3Anull%0D%0AInput%20name%3A%20null%2C%20Id%3Anull%2C%20NgModel%3Aresult.homeTeamScore.score%2C%20Value%3A%201%0D%0AInput%20name%3A%20null%2C%20Id%3Anull%2C%20NgModel%3Aresult.awayTeamScore.score%2C%20Value%3A%202
I think you need to embed the data in XML within the body of your PUT request as documented in the Import REST API docs.
Html forms only support GET or POST. So i would suggest you to post the form data using POST method instead of PUT. So that the form content will go into the body of the message and you will able to evade the URL restriction

What does 'Accept: */*' mean under Client section of Request Headers?

I was comparing headers of same HTTP Post request for Firefox and Internet Explorer and I see that for IE.
I was wondering:
What does Accept: */* mean under Client section of Request Headers?
The accept: header defines the content type the client accepts, or expects to be returned by the server. Depending on the situation this can be text/css, text/html, image/png, .. etc. - just some mime type.
The * character is considered the wildcard. accept: */* simply means that any data of whatever mimetype is accepted and the server may choose what to return to the requesting client.
It's answered in the specification. See http://greenbytes.de/tech/webdav/rfc2616.html#header.accept and http://greenbytes.de/tech/webdav/draft-ietf-httpbis-p2-semantics-21.html#header.accept

multipart/mixed HTTP request in actionscript

Is there an easy way to make an multipart/mixed HTTP request in as3?
I'm trying to reach LightSwitch server using OData protocol from flash. To send multiple commands at once you can combine them in one batch using HTTP request with "multipart/mixed" content type.
Here an example of HTTP requests with two commands:
Content-Type:multipart/mixed; boundary=batch
--batch
Content-Type: multipart/mixed; boundary=changeset
--changeset
Content-Type: application/http
Content-Transfer-Encoding: binary
PUT http://localhost:18065/ApplicationData.svc/Orders(3)/$links/User HTTP/1.1
Content-Type: application/json;odata=verbose
{"uri": "http://localhost:18065/ApplicationData.svc/Users(4)"}
--changeset
Content-Type: application/http
Content-Transfer-Encoding: binary
MERGE http://localhost:18065/ApplicationData.svc/Users(3) HTTP/1.1
Content-Type: application/json;odata=verbose
If-Match: W/"X'0000000000002715'"
{"Name": "User 3_"}
--changeset--
--batch--
Every part contains own HTTP headers and body. Response formatted the same way, with own http response code.
How to work with multiple HTTP requests in actionscript?