0

I have send a resume to a company which prefers candidates post a JSON object to specific url.

When I use cURL with PHP to post the data I get a data error unless I delete the name attribute of the data and send only the JSON text.

How do they get the data at the server end without a name?

This is the request I'm sending:

POST / HTTP/1.1
Host: www.xxx.com
Accept: */*
Content-Length: 485
Content-Type: application/x-www-form-urlencoded

{"job_code":"xxx","position":"xxx",...}
Sabuj Hassan
  • 38,281
  • 14
  • 75
  • 85
Rockman12352
  • 101
  • 10
  • 1
    possible duplicate of [How to get body of a POST in php?](http://stackoverflow.com/questions/8945879/how-to-get-body-of-a-post-in-php) – Quentin Apr 03 '14 at 08:26
  • `Content-Type: application/x-www-form-urlencoded` is wrong. If you are sending JSON then you aren't sending URL encoded data. It should be `application/json`. – Quentin Apr 03 '14 at 08:26
  • @Quentin Thank you for your answer. The link i have read before, but i do not read seriously, it is the answer i want. Thanks again~ – Rockman12352 Apr 03 '14 at 08:38

1 Answers1

-1

I am answering regarding your final try. This is how you can POST json from curl commandline:

curl -X POST "http://www.example.com" -d -H "Content-Type: application/json" "{\"job_code\":\"xxx\",\"position\":\"xxx\"}"

And to read the data from the server side without the key name, here it is:

$json_data = file_get_contents('php://input');

If you want, you can put a check on the Content-Type request header.

Sabuj Hassan
  • 38,281
  • 14
  • 75
  • 85