What is the purpose of X-Cloud-Trace-Context? - http

I was practicing some HTTP Post requests with a post-test server (ptsv2.com).
After a successful post, I can see the request body and headers etc. on the site.
There is one value that I am unsure about:
X-Cloud-Trace-Context
What is this for?? I understand the rest of header data, but I can't seem to find a good explanation on that one part.
Thank you.

X-Cloud-Trace-Context is a header from Google Cloud Platform to identify the current request.
It is particularly useful for correlating logs. As per documentation (https://cloud.google.com/appengine/docs/standard/python3/writing-application-logs), correlation has to be done manually. This post explains in detail how to do it: https://code.luasoftware.com/tutorials/google-app-engine/app-engine-standard-python37-correlate-application-log-with-request-log/

Related

Google Analytics 4 measurement protocol not working

I tried to send event to Google Analytics 4 using the postman.
And GA4 just response 204 No Content and the event is not recorded in the data stream.
I checked the measurement_id and api_secret has right value.
Is there anything wrong?
Thank you.
I encountered this issue today.
For me personally, it turns out I was looking for my received data in the wrong place: I was looking in Admin > Data Streams, which incorrectly told me "No data received in past 48 hours."
Where I actually needed to look was in the "Realtime Overview" (Reports > Realtime - see picture):
In there, there was a handy little event counter that showed me my events were, in fact, getting through just fine.
If you check here and it's still zero, here are some other things to try:
You may need to set the Content-Type header to "application/json".
Validate your events by sending them to the endpoint https://www.google-analytics.com/**debug**/mp/collect rather than https://www.google-analytics.com/**debug**/mp/collect - as long as you get "validationMessages": [] back, you should be good to go.
Make sure the JSON you're sending matches this format
According to the folks over at this similar StackOverflow question, You may need to set the User-Agent header, though I personally did not have to.
The object should be payload, not body.
Try to see this video: https://youtu.be/WSxdrG1G_yE

JSON RouteLinks response to identify traffic light

I am sending an RME request to obtain speed limit and traffic light information and get back a JSON response. As Here-API provides a lot of different traffic sign types I dont care for (e.g. overtaking etc.) I cannot figure out how those types I am interested in are numerically encoded.
Browsing through the online docs provided by Here I could did not find the information I'm looking for, i.e. enumeration codes assigned to traffic lights
The request I send out looks something like
https://rme.api.here.com/2/matchroute.json?
app_id=<my-app_id>
&app_code=<my-app-code>
&routemode=car
&file=<zip and base64 encoded route info>
&attributes=BASIC_HEIGHT_FCn(*),ROAD_GEOM_FCn(*),ADAS_ATTRIB_FCn(*)
&attributes=ADAS_ATTRIB_FCn(*),SPEED_LIMITS_FCn(*),TRAFFIC_SIGN_FCn(*)
Please see below documents page and go to layers section and check the currently supported layers with the resource Layers.
https://developer.here.com/documentation/fleet-telematics/dev_guide/topics/here-map-content.html
For examples, this link will show about the layer of TRAFFIC_SIGN_FC1 in detail.
https://fleet.api.here.com/1/doc/layer.html?region=WEU&layer=TRAFFIC_SIGN_FC1&app_id={{app_id}}&app_code={{app_code}}

LinkedIn v2 organization API endpoint failing

I'm currently requesting scopes w_company_admin, r_basicprofile, and rw_organization.
I already posted a similar question here, but I got no support so I'm trying a different approach.
I found another endpoint that should get me the organization name. I used this endpoint to get ID of organizations:
https://api.linkedin.com/v2/organizationalEntityAcls?q=roleAssignee&role=ADMINISTRATOR&start=0&count=100&fields=organizationalTarget&oauth2_access_token='.$oauth_token;
Then when I extract the ID from urn leaving me with just ID number I use that in this request
https://api.linkedin.com/v2/organizations/'.$company_id.'?projection=(elements*(entity~(vanityName)))&oauth2_access_token='.$oauth_token;
The problem is that this request is returning 200 status with the output being "{}".
I don't understand why no data would be returned? It seems like the API request is failing considering the first request worked successfully.
I can replicate the problem, you should use a different projection.
Use this:
projection=(vanityName)
Instead of this:
projection=(elements*(entity~(vanityName)))
Probably the doc here seems misleading about the usage of the decorator in this case.
Hope this help
Reposted an answer to your original question:
I found the answer on this page: https://learn.microsoft.com/en-us/linkedin/shared/references/migrations/permissions-resources-mapping
"rw_organization_admin" is the missing scope.

Request GA statistic data for a specific large set of pages

I've spent last few days trying to find a solution to solve problem below.
I have set of URLs for which I would like to request data - mainly pageviews and visits by months in specific time interval. These URL specify one web section and we would like to get statistics for this section. I'm using PHP GAPI.
I am able to construct correct filter for the URL set:
ga:pagePath==[url1]||ga:pagePath==[url2]||ga:pagePath==[url3]...
But this works for a fews URLs because request is sent via GET and there is request length limitation for GET.
At first I tried to make severeal requests for a few URLs from the whole set and after all requests (when I had data for all pages) I made sum of pageviews and visits. Than I realized that this could work for pageviews but not for visits (one particular visit could be counted in more than one response and thanks to sum it was counted muliple times).
And than i have these limitations:
I can't use regular expresion to shorten the filter. URLs of pages are badly designed (not thanks to us :) ) and the pages in a web section therefore don't have nice URL prefix like /my-section/*
I need historical data (2 years back), so it won't help to start tracking some custom variable or event for pages in particular web section from now.
So I tried to make POST request to API. I was able to get auth token, but POSTing request to get statistic data returns:
403 Forbidden
Target feed is read-only
I tried to find if there is actualy the possibility to use POST method, but had no luck finding exact info (some clues suggest that it is not possible).
Another idea could be redesigning URL to have some nice prefix to filter by regexp and somehow changing the stored URLs in GA, but I have a feeling that it's not possible either.
Does anyone have an idea how to solve this?
Thanks for any suggests :)

Why is the GET method faster than POST in HTTP?

I am new to web programming and just curious to know about the GET and POST methods of sending data from one page to another.
It is said that the GET method is faster than POST but I don't know why.
One reason I could find is that GET can take only 255 characters?
Is there any other reason? Please someone explain to me.
It's not much about speed. There are plenty of cases where POST is more applicable. For example, search engines will index GET URLs and browsers can bookmark them and make them show up in history. As a result, if you take actions like modifying a DB based on a GET request, it might be harmful as some bots might also traverse the URL.
The other case can be security issue. If you post credentials using GET, it'll get listed in browser history and server log files.
There are several misconceptions about GET and POST in HTTP. There is one primary difference, GET must be idempotent while POST does not have to be. What this means is that GETs cause no side effects, i.e I can send a GET to a web application as many times as I want to (think hitting Ctrl+R or F5 many times) and the requests will be 'safe'
I cannot do that with POST, a POST may change data on the server. For example, if I order an item on the web the item should be added with a POST because state is changed on the server, the number of items I've added has increased by 1. If I did this with a POST and hit refresh in the browser the browser warns me, if I do it with a GET the browser will simply send the request.
On the server GET vs POST is pure convention, i.e. it's up to me as a developer to ensure that I code the POST on the server to not repeat the call. There are various ways of doing this but that's another question.
To actually answer the question if I use GET or POST to perform the same task there is no performance difference.
You can read the RFC (http://www.w3.org/Protocols/rfc2616/rfc2616.html) for more details.
Looking at the http protocol, POST or GET should be equally easy and fast to parse. I would argue, there is no performance difference.
Take a look at the raw HTTP headers
http GET
GET /index.html?userid=joe&password=guessme HTTP/1.1
Host: www.mysite.com
User-Agent: Mozilla/4.0
http POST
POST /login.jsp HTTP/1.1
Host: www.mysite.com
User-Agent: Mozilla/4.0
Content-Length: 27
Content-Type: application/x-www-form-urlencoded
userid=joe&password=guessme
From my point of view, performance should not be considered when comparing GET and POST.
You should think of GET as "a place to go", and POST as "doing something". For example, a search form should be submitted using GET because the search result page is a "place" and the user will want to bookmark it or retrieve it from their history at a later date. If you submit the form using POST the user can only recreate the page by submitting the form again. On the other hand, if you were to perform an action such as clicking a delete button, you would not want to submit this with GET, as the action would be repeated whenever the user returned to the URL.
Just my few cents from 2016.
I am creating a simple message system. At first I used POST to receive new alerts. In jQuery I had:
$.post('/a/alerts', 'stamp=' + STAMP, function(result)
{
});
And in PHP I used $_POST['stamp']. Even from localhost I got 90-100 ms for every request like this.
I simply changed:
$.get('/a/alerts?stamp=' + STAMP, function(result)
{
});
and in PHP switched to $_GET['stamp']. So a little less than 1 minute of changes. Now every request takes 30-40 ms.
So GET can be twice as fast as POST. Of course not always but for small amounts of data I get same results all the time.
GET is slightly faster because the values are sent in the header unlike the POST the values are sent in the request body, in the format that the content type specifies.
Usually the content type is application/x-www-form-urlencoded, so the request body uses the same format as the query string:
parameter=value&also=another
When you use a file upload in the form, you use the multipart/form-data encoding instead, which has a different format. It's more complicated.
I agree with other answers, but it was not mentioned that GET requests can be cached while POST requests are never cached. I think this is the main reason for some GET request being performed faster.
(Of-coarse this means that sometimes no request is actually sent. Hence it's not actually the GET request which is faster, but your browser's cache.)
HTTP Methods: GET vs. POST: http://www.w3schools.com/tags/ref_httpmethods.asp
POST will grow your headers more, just making it larger, but the difference ought to be negligible really, so I don't see why this should be a concern.
Just bear in mind that the proper way to speak HTTP is to use GET only for actions and POST for data. You don't have to, but you also don't want to have a case where Google bots can, for example, insert, delete or manipulate data that was only meant for a human to handle simply because it is following the links it finds.

Resources