How to interpret CURL headers sent by user - php

I am creating an API using Laravel and Apache as the backend. My predicament is this, when I type a curl command in my terminal like,
curl -H "API KEY: NIKAPIKEY" --data "param1=value1&param2=value2" http://localhost:8888/awesome-calendar/public/config
How do I read the header API KEY in my php backend? Like I can read the POST parameters as $_REQUEST.

Answered by #nogad
The function apache_request_headers acts like the var_dump for all HTTP headers
http://php.net/manual/en/function.apache-request-headers.php

Related

Making XMLHttpRequest from php

I want to do some m2m-communication, where my server is to emulate a human operating a webpage.
So I'm trying to SEND an XMLHttpRequest from php TO another server.
Whatever I've searched for gives how for php to ACCEPT a XMLHttpRequest
I have debugged the browser, and Chrome webdeveloper tools have given me a cURL cmd which works.
The curl cmd ends in
--data-binary '[{"productNumber":"12345678","quantity":1}]'
I'm using snoopy to send the requests, and have emulated every cookie and header, but the server still responds with 400 Invalid Request.
I think the problem lies in that snoopy usually is used like this:
$submit_vars['email'] = "johndoe#example.com";
$submit_vars['password'] = 'secret';
$snoopy->submit($submit_url, $submit_vars);
i.e. Snoopy expects an array of form variables, not a string.
Is there a way to make snoopy send the equivalent of curl --data-binary ?

Accessing webpage using cURL - Issue with redirect

I am trying to access the following URL using cURL:
http://bizsearch.penrithcity.nsw.gov.au/eplanning/Pages/XC.Track/SearchApplication.aspx
However, when I attempt to access the web page I am redirected to:
http://bizsearch.penrithcity.nsw.gov.au/eplanning/Common/Common/terms.aspx
I tried utilizing the following cURL command to get passed this:
curl --cookie-jar "CookieTest.txt" url(common terms) -d "ctl00$ctMain1$chkAgree$chk1=on&ctl00$ctMain1$BtnAgree=I Agree"
curl --cookie "CookieTest.txt" url(search application)
Any help would be greatly appreciated as I am new to cURL and am having difficulty troubleshooting. I am wanting to pull the XML from the search application page.

Unable to POST file through curl using advanced rest client

Sending file to a php script works fine with curl from terminal but not through advanced rest client or postman.
Curl request-
curl -v --form filename=#/cus-check.json --form name=Upload http://127.0.0.1/cus.php
When sending the same request through ARC or Postman, the $_POST variable in php script returns an empty array.
Images

following url: curl couldn't resolve host 'GET'

I have a page (realized with a php framework) that add records in a MySQL db in this way:
www.mysite.ext/controller/addRecord.php?id=number
that add a row in a table with the number id passed via post and other informations such as timestamp, etc.
So, I movedo my eintire web applicazione to another domain and all HTTP requests works fine from old to new domain.
Only remaining issue is the curl: I wrote a bash script (under linux) that run curl of this link. Now, obviously it does not works because curl returns an alert message in which I read the page was moved.
Ok, I edited the curl sintax in this way
#! /bin/sh
link="www.myoldsite.ext/controlloer/addRecord.php?id=number"
curl --request -L GET $link
I add -L to follow url in new location but curl returns the error I wrote in this topic title.
It would be easier if I could directly modify the link adding the new domain but I do not have physical access to all devices.
GET is the default request type for curl. And that's not the way to set it.
curl -X GET ...
That is the way to set GET as the method keyword that curl uses.
It should be noted that curl selects which methods to use on its own depending on what action to ask for. -d will do POST, -I will do HEAD and so on. If you use the --request / -X option you can change the method keyword curl selects, but you will not modify curl's behavior. This means that if you for example use -d "data" to do a POST, you can modify the method to a PROPFIND with -X and curl will still think it sends a POST. You can change the normal GET to a POST method by simply adding -X POST in a command line like:
curl -X POST http://example.org/
... but curl will still think and act as if it sent a GET so it won't send any request body etc.
More here: http://curl.haxx.se/docs/httpscripting.html#More_on_changed_methods
Again, that's not necessary. Are you sure the link is correct?

How to pass POST parameters to Chromium via the command line?

I use chromium --ingognito www.mysite.com/page.php?msg=mymessage to open my website and pass it a msg.
I wish to know how to pass the same msg param via POST instead to use GET, from command line.
Do you do anything with the site in Chromium after opening it? Otherwise you could use a more capable command line http client like curl(1) which would make this very easy.
See this example:
curl --data "param1=value1&param2=value2" http://example.com/resource.cgi
With console ? I don't know, but you can try to use this extension : Advanced REST Client.
The web developers helper program to create and test custom HTTP requests.
Here is the link : https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo

Categories