I am using react-native-mapbox-gl in my react-native app. I want to send a feature request to WMS server. In openlayer I found a solution
MyLayer.getSource()
.getGetFeatureInfoUrl(
evt.coordinate,
map.getView().getResolution(),
map.getView().getProjection(),
{
'INFO_FORMAT': 'application/json',
'propertyName': 'OBJECTID,HOUSE_NUM'
}
);
This creates an URL of feature request. Is there any alternative method for "getGetFeatureInfoUrl" in mapbox-gl. Example will be very helpful.
There is no direct support for constructing a GetFeatureInfo request in Mapbox-GL-JS. You will need to construct it yourself, and make your own HTTP request.
Related
I am using Perl WWW::Mechanize::Chrome to automate a JS heavy website.
In response to a user click the page among many other requests, requests and loads a JSON file using XHR.
Is there some way to save this particular JSON data to a file?
To intercept requests like that, you generally need to use the webRequest API to filter and retrieve specific responses. I do not think you can do that via WWW::Mechanize::Chrome.
WWW::Mechanize::Chrome tries to give you the content of all requests, but Chrome itself does not make the content of XHR requests available ( https://bugs.chromium.org/p/chromium/issues/detail?id=457484 ). So the approach I take in (for example ) Net::Google::Keep is to replay the XHR requests using plain Perl LWP requests by copying the cookies and parameters from the Chrome requests-
Please note that the official support forum for WWW::Mechanize::Chrome is https://perlmonks.org , not StackOverflow.
I'm developing a messenger bot for facebook graph API and I want to sent batched requests with id. However, at some point, Facebook just doesn't catch them.
The documentation is not very helpful (the only thing I found: https://developers.facebook.com/docs/graph-api/making-multiple-requests)
The point is, I'm sending such a request to API (one batched request for demo purposes):
URL : https://graph.facebook.com/v2.6/
Headers:
Content-Type: application/json
Body:
access_token=XXXXXXX&batch=[{"method":"POST","headers":{"name":"Content-Type","value":"application/json; charset=UTF-8"},"relative_url":"me/messages","body":"%7B%22recipient%22%3A%7B%22id%22%3A%22YYYYY%22%7D%2C%22message%22%3A%7B%22attachment%22%3A%7B%22type%22%3A%22template%22%2C%22payload%22%3A%7B%22template_type%22%3A%22generic%22%2C%22elements%22%3A%5B%7B%22title%22%3A%22test%22%2C%22subtitle%22%3A%22test%20test%22%2C%22item_url%22%3A%22%22%2C%22image_url%22%3A%22https%3A%2F%2Fdata.fideinc.com%2Fcustom%2Fent_19286B%2Fid_1ABEA3C_image.png%22%2C%22buttons%22%3A%5B%7B%22type%22%3A%22element_share%22%7D%2C%7B%22type%22%3A%22postback%22%2C%22title%22%3A%22%5Cud83e%5Cudd11%20%5Cu0410%5Cu043a%5Cu0446%5Cu0438%5Cu0438%20%5Cu0432%20%5Cu0437%5Cu0430%5Cu0432%5Cu0435%5Cu0434%5Cu0435%5Cu043d%5Cu0438%5Cu0438%22%2C%22payload%22%3A%22offers%22%7D%5D%7D%5D%2C%22image_aspect_ratio%22%3A%22horizontal%22%7D%7D%7D%2C%22tag%22%3Anull%7D","access_token":"XXXXXXX"}]
Whatever format I used for the body element, it just responds: "{\"error\":{\"message\":\"(#100) The parameter recipient is required\",\"type\":\"OAuthException\",\"code\":100,\"fbtrace_id\":\"AHiM+KytmHB\"}}"
For every body element.
Other body encodings I tried:
"{\"recipient\":{\"id\":\"YYYYY\"},\"message\":{\"attachment\":{\"type\":\"template\",\"payload\":{\"template_type\":\"generic\",\"elements\":[{\"title\":\"test\",\"subtitle\":\"test test\",\"item_url\":\"\",\"image_url\":\"https://data.fideinc.com/custom/ent_19286B/id_1ABEA3C_image.png\",\"buttons\":[{\"type\":\"element_share\"},{\"type\":\"postback\",\"title\":\"\\ud83e\\udd11 \\u0410\\u043a\\u0446\\u0438\\u0438 \\u0432 \\u0437\\u0430\\u0432\\u0435\\u0434\\u0435\\u043d\\u0438\\u0438\",\"payload\":\"offers\"}]}],\"image_aspect_ratio\":\"horizontal\"}}},\"tag\":null}"
messages=%257B%2522recipient%2522%253A%257B%2522id%2522%253A%2522YYYYY%2522%257D%252C%2522message%2522%253A%257B%2522attachment%2522%253A%257B%2522type%2522%253A%2522template%2522%252C%2522payload%2522%253A%257B%2522template_type%2522%253A%2522generic%2522%252C%2522elements%2522%253A%255B%257B%2522title%2522%253A%2522test%2522%252C%2522subtitle%2522%253A%2522test+test%2522%252C%2522item_url%2522%253A%2522%2522%252C%2522image_url%2522%253A%2522https%253A%2F%2Fdata.fideinc.com%2Fcustom%2Fent_19286B%2Fid_1ABEA3C_image.png%2522%252C%2522buttons%2522%253A%255B%257B%2522type%2522%253A%2522element_share%2522%257D%252C%257B%2522type%2522%253A%2522postback%2522%252C%2522title%2522%253A%2522%5Cud83e%5Cudd11+%5Cu0410%5Cu043a%5Cu0446%5Cu0438%5Cu0438+%5Cu0432+%5Cu0437%5Cu0430%5Cu0432%5Cu0435%5Cu0434%5Cu0435%5Cu043d%5Cu0438%5Cu0438%2522%252C%2522payload%2522%253A%2522offers%2522%257D%255D%257D%255D%252C%2522image_aspect_ratio%2522%253A%2522horizontal%2522%257D%257D%257D%252C%2522tag%2522%253Anull%257D"
And so on
P.S. I can't use any external Facebook SDK in my project, I just need to get this request right
In case someone has the same problem, the answer is incredibly simple: use http_build_query instead of json_encode...
Does Syncfusion Dashboard web data source support POST http methods?
If yes, so how set it up?
Thanks!
HTTP Post requests additional data from client to server in the message body, where message body will be like JSON, XML, TEXT etc. This may result in the creation of a new resource or the updates of existing resources or both. In contrast, HTTP Get requests include all required data in the URL. So we support HTTP Get method since POST method is not valid use case.
Regards,
Umapathy S.
I want to make a wms request using L.tileLayer.wms, Is there a way to add a request header to the request for authorization purposes? If not what would be a good possible workaround?
you can use leaflet-wms-header plugin https://github.com/ticinum-aerospace/leaflet-wms-header or try to create a custom wms layer as in this example https://github.com/ticinum-aerospace/leaflet-wms-header/blob/master/index.js
I am beginning to use SailsJS and i found it wonderful and powerful.
Can anybody please explain me how to send POST and GET requests to an API outside Sails and where do i actually write this request?
Thanks a lot and Happy 2016 everyone!!!
Edit:
Hello #arcseldon, thank you for been trying to help me.
I'll try to explain myself better, and show you my code.
I have an API, written in php (which i think is not relevant) which accepts POST, GET, PUT, DELETE methods. I use Postman for testings and everything looks OK.
I am trying to make an app in Sails, which GETs and POSTs requests to my API, but i dont know where is the best place to put the GET's and POST's codes.
In the model i already have the following to ask for a token to perform the other requests, and it works:
gettoken: function (requestnewtoken,tokenresult) {
if(!requestnewtoken) {
tokenresult(global.tokeng);
} else {
request({
headers: {
'User-agent' : 'develop',
'Content-Type' : 'application/x-www-form-urlencoded;charset=UTF-8',
'Content-Length' : '29',
'Authorization' : 'Basic ' + global.idsecret
},
uri: "https://myapi/oauth2/token",
method: "POST",
form: {
grant_type: "client_credentials"
}
}, function(error, response, body) {
var tokenjson = JSON.parse(body);
var token = tokenjson['access_token'];
global.tokeng = token;
tokenresult(token);
});
}
}
Then, i perform a GET request to another endpoint, which works:
listpublicroutes: function(requestnewtoken,cb) {
Model.gettoken(requestnewtoken,function(token) {
request({
headers: {
'Authorization' : 'Bearer ' + token
},
uri: "https://myapi/folder/file.json",
method: "GET",
timeout: 10000,
followRedirect: true,
maxRedirects: 10
}, function(error,response, body) {
if(error || (response.statusCode != 200)) {
Model.listpublicroutes(true,cb);
} else {
cb(null,JSON.parse(body));
}
});
});
}
My doubts are if this is the best way to write a POST and GET request or they could be more simple, and if the requests should be done in the controller (or anywhere else) instead of the model.
Can you give me an example of a POST and GET request?
Thanks a lot to everyone who's trying to understand me.
Your question isn't clear exactly what you are asking... Here are a few suggestions depending on what you wish to do.
If you are trying to call out and make an http request from within
server-side Sails code then I would recommend you take a look at the
NPM module request.
If you are talking about making get / post requests to test your API,
then use a web browser plugin / tool such as postman (also a
Chrome plugin of same name).
If you are talking about calling a completely different domain URL
using AJAX from within your web application client (via web browser)
then you can just use any AJAX approach (jquery / angular / whatever
client library you are using to make ajax calls) but be aware that the
domain you are calling to would have to have been setup with a cross
origin resource sharing (CORS).
You have control over your own CORS settings (allowing apps originating from other domains to call into your sails API from the browser, by updating config/cors.js settings.
Does this answer your question? If you need further help leave me a message below, and I'll try to assist.
Update Based On Question Update:
#Michi - ok, you wish to call your PHP api from within SailsJS - the three contenders in terms of location to do this are inside a Controller, a custom Model method, or within a custom service.
My "recommendation" is that most of the time, this logic sits within a Controller if it is logic that doesn't really need to be shared elsewhere. You could conceivably call into a Model.method(), but "usually" you want to think of the models as your domain data (certainly not always, if the responsibility for what you are doing truly belongs to a single Model etc which owns all the state interaction then the model might be the right place to locate that responsibility).
However, in your case, you are getting a token, and without seeing your model code (you have just provided the getToken function which doesn't really look like it is tied to a particular model..?) then I would say opt to invoke it within your controller if not needed elsewhere. Otherwise, refactor it out into a service. To quote the SailsJS documentation:
Services can be thought of as libraries which contain functions that
you might want to use in many places of your application. For example,
you might have an EmailService which wraps some default email message
boilerplate code that you would want to use in many parts of your
application. The main benefit of using services in Sails is that they
are globalized--you don't have to use require() to access them.
I have frequently put custom logic in Controllers, Models and Services, but for networking related logic etc, my preference is:
Controller if one-off logic.
Service if reusability required, or encapsulating the code as service improves readability / maintenance of the app
Use a model, only if you strongly believe the logic and responsibility is truly tied to that model - err on the side of caution here and use sparingly. But I acknowledge my recommendations may be construed as subjective - am basing them on what I believe to be good OOP practices in general terms.