Here's the code I'm working with currently: var request = require('request');  var options = {   'method': 'GET',   'url': `https://accounts.rec.net/account?username=actuallylegacy`,   'headers': {   } };  request(options, function (error, response) {   if (error) throw new Error(error);   if (!response.body) { console.log(&quot;No user found by that name!&quot;) return } else {   console.log(response.body); }  This code outputs this: {&quot;accountId&quot;:5225334,&quot;username&quot;:&quot;ActuallyLegacy&quot;,&quot;displayName&quot;:&quot;Le_acy&quot;,&quot;profileImage&quot;:&quot;52a12fa7a7f5436491a6205fddf00f37.jpg&quot;,&quot;bannerImage&quot;:&quot;9939bd49de624ff0b236d366a95ff7af.jpg&quot;,&quot;isJunior&quot;:false,&quot;platforms&quot;:4,&quot;createdAt&quot;:&quot;2020-05-13T19:05:26.6584486Z&quot;}  Which this is super messy, which I don't like. My goal is to be able to pull parts of this data and display it all in different &quot;blocks&quot;. I'm not sure whether I'm just looking in the wrong places for help but, I haven't been able to find any sort of guide on how to extract data from a string. Any sort of help would be greatly appreciated! ^w^
2361
Given a string of JSON data, how can I safely turn that string into a JavaScript object?  Obviously I can do this unsafely with something like:  var obj = eval("(" + json + ')');   but that leaves me vulnerable to the JSON string containing other code, which it seems very dangerous to simply eval.
100844
on Ask Different appears to have no name due to invisible Unicode characters:    he's the #2 user on the site:    Why is that allowed? I think it is confusing for users, e.g. when they will see at the bottom of an answer:    It's not clear who answered, not clear what the rep numbers and badges are related to, and not clear how you can @reply to that user in the comments!
34618
I create a small API for one project using Bathic Authentication. The API consists of some custom paths defined in routes in a custom module. Using JsonResponse() in the controller we send back a JSON object with data.  But in case the user does not have permissions to access the path the route gives back the 404 HTML page. How can I tell Drupal to return a JSON object for my API paths under every circumstances?  Another example: we defined just to accept GET in the route. Using POST will return a HTML error page - we want Drupal to send back JSON with error information.
106043
I have a C# application that scans a directory and gathers some information.  I would like to display the account name for each file.  I can do this on the local system by getting the SID for the FileInfo object, and then doing:  string GetNameFromSID( SecurityIdentifier sid ) {     NTAccount ntAccount = (NTAccount)sid.Translate( typeof( NTAccount ) );     return ntAccount.ToString(); }   However, this does not work for files on a network, presumably because the Translate() function only works with local user accounts.  I thought maybe I could do an LDAP lookup on the SID, so I tried the following:  string GetNameFromSID( SecurityIdentifier sid ) {     string str = "LDAP://&lt;SID=" + sid.Value + "&gt;";     DirectoryEntry dirEntry = new DirectoryEntry( str );     return dirEntry.Name; }   This seems like it will work, in that the access to "dirEntry.Name" hangs for a few seconds, as if it is going off and querying the network, but then it throws a System.Runtime.InteropServices.COMException  Does anyone know how I can get the account name of an arbitrary file or SID?  I don't know much about networking or LDAP or anything.  There's a class called DirectorySearcher that maybe I'm supposed to use, but it wants a domain name, and I don't know how to get that either - all I have is the path to the directory I'm scanning.  Thanks in advance.
109323
Python frameworks always provide ways to handle URLs that convey the data of the request in an elegant way, like for example   I want you to notice the ending path /userid/123424/  How do you do this in ASP.NET?
20853
Is there a way to perform an HTTP GET request within a Visual Basic script?  I need to get the contents of the response from a particular URL for processing.
119203
Using AMPScript to parse an XML feed. Client is switching to JSON. Is there something similar to  for JSON in AMPScript? I am confined to using the members login area and not an external API application.
11741
How do you safely encode a URL using JavaScript such that it can be put into a GET string?  var myUrl = "http://example.com/index.html?param=1&amp;anotherParam=2"; var myOtherUrl = "http://example.com/index.html?url=" + myUrl;   I assume that you need to encode the myUrl variable on that second line?
100115
I'm creating a mobile app in Ionic (which uses Angular). I've set up a D8.3-dev BE which will hold the users and their data.  I've figured out how to register as an anonymous user (this is why I'm using D8.3-dev because this functionality is introduced here) and wrote a blog post about it ().  Logging in also works after I registered a user.  This is how I login:    /*    * Login User with username and password.    */   login: function (email, password) {      var defer = $q.defer();      $http({       method: 'POST',       url: config.endpoint + '/user/login?_format=json',       data: {         name: email,         pass: password       },     })       .success(function (data, status, headers, config) {          // Store the CSRF token.         localStorage.set('csrf_token', data.csrf_token);          // Store the Logout token         localStorage.set('logout_token', data.logout_token);          // Set the user object.         localStorage.setObject('user', data.current_user);          defer.resolve(data);       })       .error(function (data, status, headers, config) {         defer.reject(data);       });      return defer.promise;   },   When logging in I receive the following:  current user object, a csrf_token and a logout_token.  When I use these tokens to logout (I tried a lot of different ways already:    /*    * Logout User.    */   logout: function () {      var defer = $q.defer();      $http({       method: 'POST',       url: config.endpoint + '/user/logout?_format=json&amp;token=' + localStorage.get('csrf_token'),       dataType: 'json',     })       .success(function (data, status, headers, config) {         defer.resolve(data);          // Go to the login page.         $state.go("login");       })       .error(function (data, status, headers, config) {         defer.reject(data);       });      return defer.promise;   },   I keep getting the following error:  {"message":"\u0027csrf_token\u0027 URL query argument is invalid."}   So it seems the crsf_token I use from logging in isn't correct.  What am I doing wrong or overseeing here?  EDIT: after testing a lot and trying it seems like I need to use get. I use this code now for logout but I still get a 403:    /*    * Logout User.    */   logout: function () {      var defer = $q.defer();      $http({       method: 'GET',       url: config.endpoint + '/user/logout?_format=json',       headers: {         'X-CSRF-Token': localStorage.get('csrf_token'),         'Authorization': 'Basic xxxxxxxxx',       },     })       .success(function (data, status, headers, config) {         defer.resolve(data);       })       .error(function (data, status, headers, config) {         defer.reject(data);       });      return defer.promise;   },   Here is what the Drupal 8.3-dev BE returns, it seems like it recognizes the user I want to log out but it's still throwing the 403.
50373
I want to capture the HTTP request header fields, primarily the Referer and User-Agent, within my client-side JavaScript.  How may I access them?    Google Analytics manages to get the data via JavaScript that they have you embed in you pages, so it is definitely possible.     Related:
123258
@RestResource(urlMapping='/Merchandise/*') global with sharing class MerchandiseManager {      @HttpGet     global static Merchandise__c getMerchandiseById() {         RestRequest req = RestContext.request;                 String merchId = req.requestURI.substring(                                   req.requestURI.lastIndexOf('/')+1);         Merchandise__c result =                         [SELECT Name,Description__c,Price__c,Total_Inventory__c                         FROM Merchandise__c                          WHERE Id = :merchId];         return result;     }      @HttpPost     global static String createMerchandise(String name,         String description, Decimal price, Double inventory) {         Merchandise__c m = new Merchandise__c(             Name=name,             Description__c=description,             Price__c=price,             Total_Inventory__c=inventory);         insert m;         return m.Id;     } }   i am trying to execute these from postman,    but throwing below error,how i can authenticate,please help urgent requirement.     {       "message": "Session expired or invalid",       "errorCode": "INVALID_SESSION_ID"   }
109761
I have getting the below JSON on using JSON.serialize  [ {   "lname" : "Singh",   "hcpZipCode" : null,   "hcpState" : null,   "hcpEmail" : "test@test.com",   "hcpCity" : null,   "hcpAddLine1" : null,   "fname" : "Abhey",   "countryCode" : "AUS" } ]   I don't know why this '[' is coming at the begining.I don't need this '[' at the begining due to which I am getting System.JSONException: Malformed JSON: Expected '{' at the beginning of object  code     public PageReference step2() {         string JSONstr='';        List&lt;HCPRequest&gt; conWrapList = new List&lt;HCPRequest&gt;();        HCPRequest tempcontactWrapper = new HCPRequest();        tempcontactWrapper.fname='Abhey';        tempcontactWrapper.lname='Singh';        tempcontactWrapper.countryCode='AUS';        tempcontactWrapper.hcpEmail=contact.Email;         conWrapList.add(tempcontactWrapper);          JSONstr = JSON.serializePretty(conWrapList);         System.debug('\n******'+JSONstr +'\n******');          String clientId = 'xy';         String clientSecret = 'x';          //We can also store our username password in custom setting.         String username='x';//salesforce username          String password='x';//password+securitytoken         // Generating the Access Token         HttpRequest req = new HttpRequest();         req.setMethod('POST');         req.setEndpoint('https://test.salesforce.com/services/oauth2/token');// this is the OAuth endpoint where this request will be hit         req.setBody('grant_type=password&amp;client_id='+clientId+'&amp;client_secret='+clientSecret+'&amp;username='+username+'&amp;password='+password);          Http http = new Http();         HTTPResponse res = http.send(req);         String str = res.getBody();         wrapObj = (Wrapper)Json.deserialize(str,Wrapper.class);         accessToken = wrapObj.access_token;         instanceUrl = wrapObj.instance_url;          HttpRequest req1 = new HttpRequest();         string response='';         req1.setMethod('POST');         //req.setEndpoint(wrapObj.instance_url+'/services/apexrest/Account/getAccountById?name=champaKAli');         string EndPt = 'y';         string email='test@test.com';         req1.setEndpoint(EndPt);         req1.setHeader('Authorization', 'OAuth '+wrapObj.access_token);          req1.setHeader('Content-Type', 'application/json');          //req1.setBody('{"request":{"lname" : "Singh","hcpZipCode" : null,"hcpState" : null,"hcpEmail" : "test@test.com","hcpCity" : null,"hcpAddLine1" : null,"fname" : "Abhey","countryCode" : "AUS"}}');          req1.setBody('{"request":'+JSON.Serialize(conWrapList)+'}');          //req.setBody('{"request": {"countryCode": "AUS","hcpEmail" : ""+email}}');          //req.setTimeout(60000);             //req.setHeader('Content-Length', '0');         Http http1 = new Http();         HTTPResponse res1 = http1.send(req1);          System.debug('***Response***** ' + res1.getBody());         if(res1.getBody()!=null)         {             response=res1.getBody();             HCPResponse saj=(HCPResponse)JSON.deserialize(response,HCPResponse.class);           System.debug('***Response came full***** ' + saj);            System.debug('***Response came***** ' + saj.accList);             for(HCPResponseDetail s :saj.accList)            {            System.debug('***Response email***** ' + s.hcpEmail);            System.debug('***Response add2***** ' + s.hcpAddrLine2);            contact.Address1_Line2__c=s.hcpAddrLine2;            }           //return response;         //string methodcall=methodGet(JSONstr);               return Page.opptyStep2CustomReg;         }
49912
I am trying to retrieve VersionData with a standard REST API call from a VisualForce Page a then upload it to a S3 bucket but end up with corrupted files. I believe this is an encoding problem on the client side as plain text or CSVs work like a charm. I can upload VersionData from Apex but there are heap and request size limitations so I need to send the data from the client.   This is the call and returned string, I tried changing mimeType and encoding on both sides (SF call and S3 upload) with no luck.   Any ideas how to properly process images or pdf files? Thanks a lot  THE PROBLEM IS NOW SOLVED  Files should not be treated as strings. I solved the problem by leaving jQuery's ajax as I did not succeed to request a response type. By switching to plain JS and making a GET call (XMLHttpRequest) with response type set to blob I received an Object, instead of a string. Base64 string can be then retreived using JS FileReader.
37606
I am attempting to use the Tooling API to retrieve all the data for a particular profile. According to the Tooling API documentation from v32 there is a Profile object which contains a set of ProfileMetadata. I am running the following anonymous code:  HttpRequest req = new HttpRequest(); req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID()); req.setHeader('Content-Type', 'application/json'); req.setEndpoint('https://na11.salesforce.com/services/data/v32.0/tooling/sobjects/Profile/00eA0000000WrUv'); req.setMethod('GET'); Http h = new Http(); HttpResponse res = h.send(req); system.debug(res.getBody());   The profile being referenced is a custom profile with permissions on objects etc however the debug output is as shown at   As you can see certain data is not coming through (objectPermissions is what I need out of this) and I wondered if anybody had any idea how to get that data? Thanks.
67152
I would like to create a page where all images which reside on my website are listed with title and alternative representation.  I already wrote me a little program to find and load all HTML files, but now I am stuck at how to extract src, title and alt from this HTML:  &lt;img src="/image/fluffybunny.jpg" title="Harvey the bunny" alt="a cute little fluffy bunny" />  I guess this should be done with some regex, but since the order of the tags may vary, and I need all of them, I don't really know how to parse this in an elegant way (I could do it the hard char by char way, but that's painful).
116111
I'm trying to view the actual entries, not the backend identifiers.  &gt; db.&lt;collection&gt;.find({"_id": "486b4ca55b144b119f4551417c5798c8"}).pretty()  {     "_id" : "486b4ca55b144b119f4551417c5798c8",     "date" : ISODate("2017-04-20T05:47:06.176Z"),     "content" : ObjectId("58f84b5a0318762cb6e230a6"),     "digest" : "d064a874c872d75f6ab67c04d8b79b26f65f9b4f",     "short" : "5f9b4f",     "size" : 2374694 }   Also tried mongoexport:  $ mongoexport --host 127.0.0.1 --port &lt;port&gt; -o test --pretty --db &lt;database&gt; --collection &lt;collection&gt;   This also shows backend data. I just want to see what was uploaded to the database. The actual content itself.
73621
Is there any way to create the query parameters for doing a GET request in JavaScript?  Just like in Python you have , which takes in a dictionary (or list of two tuples) and creates a string like 'var1=value1&amp;var2=value2'.