I am exploring the world of the REST API for the first time, I have already had to deal with it through the use of Slim, but now I want to be a homemade solution, considering that I don't need any framework for make a simple Rest Api. What I have done is create a page like this:  &lt;?php $method = $_SERVER['REQUEST_METHOD']; $request = explode("/", substr(@$_SERVER['PATH_INFO'], 1));  switch ($method)  {   case 'PUT':     echo "PUT";     break;   case 'POST':     echo "POST";     break;   case 'GET':     echo "GET";     break;   case 'DELETE':     echo "DELETE";       break;   default:     handle_error($request);       break; }   My goal is to implement an access token, I think passing it in the header but I'm not sure (I'm looking for a secure mode). However if I run this from the command line:  curl -X GET http://localhost/v1   I get GET, just to give an example of how it should work. And so for all other inquiries. Now the real question is: how can I call the methods in the switch only if I passed a token? For example, at the top of the page will be performed control will be carried out such a check:  if(!isset($_SERVER['AUTH_USER']))  {     exit('TOKEN not provide'); }   Another question is how to pass the token via curl? Because if I do it through ... I can read the header via curl but how would it work?  UPDATE:  As mentioned by @Paradoxis I've tried with:  url http://localhost/v1 -H "Authorization: &lt;token&gt;"   but seems that I fail to take the header. I spend my time to understand why the header isn't passed, so in my code I've add this line:  print_r(apache_request_headers());   and this is the result:  Array  (    [Host] =&gt; localhost    [User-Agent] =&gt; curl/7.46.0    [Accept] =&gt; */*    [Authorization] =&gt; &lt;token&gt; )   How you can see in the request_headers I can see correctly in the header, but I can't catch it through the use of $_SERVER['Authorization'] or $_SERVER['HTTP_Authorization']
56047
What does RESTful Authentication mean and how does it work?  I can't find a good overview on Google.  My only understanding is that you pass the session key (remeberal) in the URL, but this could be horribly wrong.
34960
Do anyone have a working REST Login on Drupal 8? This is what I tried. POST /user/login HTTP/1.1 Host: 8.d8.local Content-Type: application/x-www-form-urlencoded Accept-Encoding: http://nikhilmohan.in Cache-Control: no-cache  name=test&amp;pass=password&amp;form_id=user_login_form  It returns me HTML instead of JSON.
15283
I have a php file which I will be using as exclusively as an include. Therefore I would like to throw an error instead of executing it when it's accessed directly by typing in the URL instead of being included.  Basically I need to do a check as follows in the php file:  if ( $REQUEST_URL == $URL_OF_CURRENT_PAGE ) die ("Direct access not premitted");   Is there an easy way to do this?
84406
I have a java program that uploads a file to a document libary and i have a method that creates a folder. I want the file to be uploaded to the folder but i keeps getting uploaded outside the folder.   If i call the create folder method before the upload file method I get http 403 Forbidden error  what could be the problem?      public void createFolder(String digest) throws ClientProtocolException, IOException {         HttpPost request = new HttpPost(                 "http://industrial-ex/sites/tifdemo/_api/Web/Folders/add('enovia/newfolder')");           request.addHeader("Content-Type", "application/json;odata=verbose");         request.addHeader("X-RequestDigest", digest);         CloseableHttpResponse response = httpClient.execute(target, request, context);         response.setHeader("Accept", "application/json;odata=verbose");         System.out.println("STATUS CODE Post Folder: " + response.getStatusLine());      }
16373
How do I pass have a Javascript script request a PHP page and pass data to it? How do I then have the PHP script pass data back to the Javascript script?  client.js:  data = {tohex: 4919, sum: [1, 3, 5]}; // how would this script pass data to server.php and access the response?   server.php:  $tohex = ... ; // How would this be set to data.tohex? $sum = ...; // How would this be set to data.sum? // How would this be sent to client.js? array(base_convert($tohex, 16), array_sum($sum))
39661
I created rest resource plugin in a custom module and need to send some JSON data with the request, and access it in the post function. At the moment my post function does not do anything but return some dummy JSON data so I know it is working.  It seems that whenever I try to pass JSON data with the request, it will give me this error: "Could not denormalize object of type , no supporting normalizer found."  If I then try to get this data using file_get_contents('php://input'), it will give me a 403 forbidden error. But if I try to return the same data that I get from file_get_contents('php://input') from the post function, I get the normalizer error again.  I wasn't able to find much information on even making this REST resource and even less on this issue now, so if anyone has any input I would greatly appreciate it, thanks!
61580
What is the quickest way to HTTP GET in Python if I know the content will be a string? I am searching the documentation for a quick one-liner like:  contents = url.get("http://example.com/foo/bar")   But all I can find using Google are httplib and urllib - and I am unable to find a shortcut in those libraries.  Does standard Python 2.5 have a shortcut in some form as above, or should I write a function url_get?   I would prefer not to capture the output of shelling out to wget or curl.
41213
I've looked at this question     and many other forums with this same problem.  I'm trying to access restful webservice we created in our salesforce instance with postman.  I'm using this url  and these url params  grant_type=password client_id={my id} client_secret={my secret} username=username@domain.com password={password}{security token}   I'm getting this response  {   "error": "invalid_grant",   "error_description": "authentication failure" }   In the connected app settings, I've added my IP under trusted IPs.  I've set IP Relaxation to "Relax IP restrictions".  I set permitted users to "All users may self-authorize".  I added my IP address under Administer->Security Controls->Network Access.  Is there supposed to be a delimiter between password and security token in the password URL parameter?  I can view my connected app through two views in salesforce.    When I go to Administer->Manage Apps->Connected Apps I see it there but when I hover the mouse over it, it doesn't say "Managed-Installed" and it doesn't have the little blue arrow next to the link.  But when I click on it it says its installed  I also can view it through Develop->Remote Access which then redirects me to a page where I'm able to click on it and see the consumer key and consumer secret.  I tried sending a request from the developer console and I get the same error.  I tried sending with and without the security token appended to the password.  I do have the '@' character in the password, could that be causing a problem?  HttpRequest req = new HttpRequest(); req.setMethod('POST'); req.setEndpoint('https://login.salesforce.com/services/oauth2/token'); req.setBody('grant_type=password' +             '&amp;client_id=' + 'id'+            '&amp;client_secret=' + 'secret' +            '&amp;username=' + 'username@domain.com.currentdev' +            '&amp;password=' + 'password'); Http h = new Http(); HTTPResponse res = h.send(req); System.debug('Body ' + res.getBody()); System.debug('Status ' + res.getStatus()); System.debug('Status code ' + res.getStatusCode());   Thanks @Eric, the problem was I'm in a test environment so I should be using test.salesforce.com not login.salesforce.com
74983
I'm writing a php app to access a MySQL database, and on a tutorial, it says something of the form  mysql_connect($host, $user, $pass) or die("could not connect");   How does PHP know that the function failed so that it runs the die part? I guess I'm asking how the "or" part of it works. I don't think I've seen it before.
122983
I use PHP 5.4.3 and I want to connect to a MySQL database (DB for brevity) remotely (the PHP script resides on a different server than the DB) with normal object-oriented programming (OOP) way:  $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);   and I get the error:      Warning: mysqli::mysqli(): The server requested authentication method unknown to the client [mysql_old_password]   Connect Error (2054) The server requested authentication method unknown to the client   I found  and  but they don't seem to help. I used PHP 5.2.9 and everything worked OK, but downgrading the PHP version is not a solution for me.   I also have to mention that I don't have full access to DB's settings cause the client doesn't give me that kind of access. I told him to ask Hostgator for a newer password format support, but they answered that they cannot do anything which was not what I was expecting. I did a new effort from another remote server and I get now this:     Connect Error (1045) Access denied for user 'user'@'host' (using password: YES)   by using PHP 5.3.9. It looks like the DB doesn't "let me in" because of the remote server's PHP script, but with Oracle's Workbench everything works fine.  Thanks for your time.
85816
I need to make an AJAX request from a website to a REST web service hosted in another domain.  Although this is works just fine in Internet Explorer, other browsers such as Mozilla and Google Chrome impose far stricter security restrictions, which prohibit cross-site AJAX requests.  The problem is that I have no control over the domain nor the web server where the site is hosted. This means that my REST web service must run somewhere else, and I can't put in place any redirection mechanism.  Here is the JavaScript code that makes the asynchronous call:  var serviceUrl = "http://myservicedomain"; var payload = "&lt;myRequest&gt;&lt;content&gt;Some content&lt;/content&gt;&lt;/myRequest&gt;"; var request = new XMLHttpRequest(); request.open("POST", serviceUrl, true); // &lt;-- This fails in Mozilla Firefox amongst other browsers request.setRequestHeader("Content-type", "text/xml"); request.send(payload);   How can I have this work in other browsers beside Internet Explorer?
27997
When a PHP application makes a database connection it of course generally needs to pass a login and password. If I'm using a single, minimum-permission login for my application, then the PHP needs to know that login and password somewhere. What is the best way to secure that password? It seems like just writing it in the PHP code isn't a good idea.
44586
[I am re-posting this; I posted it as "guest" inadvertently.]  soapUI 5.5.0, community edition.  Created REST requests with parameters (style = plain). Wanted to use them in request body as variables, but that did not work. Tried "${#firstName}" and "{firstName}"  The result was  "firstName": "",[\n]"  The call works fine with all values specified.
48046
I'm looking for a way to create an HttpRequest in Apex using a POST method. When I do it, I hit this error:  {     "message": "HTTP Method 'POST' not allowed. Allowed are HEAD,GET,PATCH,DELETE",     "errorCode": "METHOD_NOT_ALLOWED" }   When I try to make a PATCH request (to update), there's an exception appearing in the developer console:  FATAL_ERROR System.CalloutException: Invalid HTTP method: PATCH   Just to give a quick background, I'm trying to use Salesforce's REST API from inside my Apex class to update an CurrencyType record. It's working outside Salesforce (using curl for example).  Thanks.
48121
Is REST a better approach to doing Web Services or is SOAP?  Or are they different tools for different problems?   Or is it a nuanced issue - that is, is one slightly better in certain arenas than another, etc?  I would especially appreciate information about those concepts and their relation to the PHP-universe and also modern high-end web-applications.
109516
I'm trying to use the HTTP Callout methods provided in Apex to  1. Get a token from Marketo 2. Use this token to create three leads in Marketo using the REST API  However, it doesn't seem to be working. I have never coded something like this before, so I expect that I probably made some very embarrassing and obvious mistakes, but I've been able to find very little documentation on this, so I'm starting from basically scratch and the REST API documentation. Anyways, here's the two classes I've been using to attempt to do this:  Class 1:  global class MakeCallouts {       static String testCallout() {          HttpResponse res = CalloutClass.getInfoFromExternalService();         String contentType = res.getHeader('Content-Type');         System.assert(contentType == 'application/json');         System.assertEquals(200, res.getStatusCode());      //getting the accesstoken       String getToken;     String answer = res.getBody();     System.debug(answer);  JSONParser parser = JSON.createParser(answer); while (parser.nextToken() != null) {     if ((parser.getCurrentToken() == JSONToken.FIELD_NAME)){         String fieldName = parser.getText();         parser.nextToken();         if(fieldName == 'access_token') {            getToken = parser.getText();               }  } } System.debug(getToken);           HttpResponse res2 = CalloutClass.getInfoFromExternalService2(getToken);           String contentType2 = res2.getHeader('Content-Type');         System.assert(contentType2 == 'application/json');         System.assertEquals(200, res2.getStatusCode());          System.debug(res2.getBody());         return res2.getBody();     } }   Class 2:  public class CalloutClass {  public static HttpResponse getInfoFromExternalService () {     // Instantiate a new http object     Http h = new Http();       // Instantiate a new HTTP request, specify the method (GET) as well as the endpoint     HttpRequest req = new HttpRequest();     req.setEndpoint('https://XXX-rlu-923.mktorest.com/identity/oauth/token?grant_type=client_credentials&amp;client_id=XXXX&amp;client_secret=XXXX');     req.setMethod('GET');      // Send the request, and return a response     HttpResponse res = h.send(req);     return res;  }   public static HttpResponse getInfoFromExternalService2 (String getToken) {     // Instantiate a new http object     Http h2 = new Http();       // Instantiate a new HTTP request, specify the method (POST) as well as the endpoint     HttpRequest req2 = new HttpRequest();     req2.setHeader('Content-Type','application/json');      req2.setMethod('POST');     req2.setEndpoint('https://XXXX.mktorest.com/rest/v1/leads.json?access_token='+getToken);     req2.setBody('{"action":"createOnly","input":[{"email":"kjashaedd-1@klooblept.com","firstName":"Kataldar-1","postalCode":"04828"},{"email":"kjashaedd-2@klooblept.com","firstName":"Kataldar-2","postalCode":"04828"},{"email":"kjashaedd-3@klooblept.com","firstName":"Kataldar-3","postalCode":"04828"}]}}');      // Send the request, and return a response     HttpResponse res2 = h2.send(req2);     return res2;  }    }   The MakeCallouts class is triggered when a Lead is created (this is entirely for testing purposes. I'm going to change the API call after I get this to work. But it's pretty obvious that the call is working when I see three new leads appear in my database, so it's a good test).
79053
I feel like this should be really easy to do, but I can't find anything about it on the web. Is there a way, through either javascript or a java web servlet, to skip the subsequent authentication?  We are trying to use the REST Api in production, but the problem is, that each time you refresh the page in javascript, or delete the cookies in java, you have to login again to salesforce.  Is there some way to do an ajax call or the login in the background or whatever, so that you can have your application connecting to salesforce right away?