Header HTTP Origin in TWebRequest - delphi

How can I get the equivalent of php:
$_SERVER['HTTP_ORIGIN']
in delphi?, I'm using TWebRequest in a WebBroker applications project (not datasnap).

It works using Request.GetFieldByName ('ORIGIN') where Request is some instance of TWebReques. However, there are "hidden" headers, to obtain them you can use a solution based on the response of the following link: Enumerate TWebRequest HTTP header fields, and save them in a TDictionary

Related

No HTTP resource was found that matches the request

I tried to replace the Page content using Microsoft Graph like this:
MultipartFormDataContent form = new MultipartFormDataContent();
form.Add( some stream contents );
var formdatastream = form.ReadAsStreamAsync();
graphClient.Users[userPrincipalName]
.Onenote
.Pages[onenotepage.Id]
.Content
.Request()
.PutAsync<OnenotePage>(formdatastream);
It returns No HTTP resource was found that matches the request, which implies that it does not accept an HTTP PUT request.
Clearly, it is saying it accepts HTTP Patch so maybe the .Net library needs to be changed?
This is a known issue and is a result of a mismatch of the service definition and the service behavior.
If you search for 'onenoteupdatepage' in the OneNote SDK tests, you can see one possible workaround for how to replace an existing page.
To update the OneNote API, you need to trigger a PATCH request like so:
PATCH https://graph.microsoft.com/v1.0/me/onenote/pages/{id}/content
{JSON PAYLOAD}
Perhaps that's not what the SDK is doing?

How to consume HTTPS webservice having wsdl and soap12 version.

While sending soap1.2 request what are the namespaces we need to use in soapbody? Any sample code available in ios programming?
SOAP request namespace start with following prefix.
http://www.w3.org/2003/05/
And depending on the type of element there are suffix. so for eg.
Envelope - http://www.w3.org/2003/05/soap-envelope
Addressing Header - http://www.w3.org/2005/08/addressing
Check This example.

AFHTTPRequestOperationManager custom http header always start with "HTTP_"?

I use AFHTTPRequestOperationManager to send HTTP request, and have some information put in the HTTP custom header, named "X-AKey".
I confirmed the header name by:
NSLog(#"%#", manager.requestSerializer.HTTPRequestHeaders);
Then, I captured the outgoing message, and found that the header name has changed to "HTTP_X_AKEY".
I've searched some questions, and found that this might be a standard way of naming custom header: "Meta-variables with names beginning with "HTTP_" contain values read from the client request header fields, if the protocol used is HTTP. The HTTP header field name is converted to upper case, has all occurrences of "-" replaced with "" and has "HTTP" prepended to give the meta-variable name."
Nevertheless, my question is: CAN I send a message with a custom header name exactly as I specified? That is, in my case, "X-AKey" instead of "HTTP_X_AKEY"?
(PS: For real applications, if both the client and server are negotiated to use the 'HTTP_xxx' format, there won't be any problem. I'm just curious about the answer for now.)
Thanks.
Try this:
[manager.requestSerializer setValue:#"SomeValue" forHTTPHeaderField:#"SomeHeaderField"]

Consuming Yellow Pages.com using FSharp Type Providers

I signed up for the yellow pages.com API program found here: https://publisher.yp.com/home.
I went to make a call like this and I am getting back JSON in the browser:
http://pubapi.atti.com/search-api/search/devapi/search?term=Jumbo+China+5&searchloc=6108+Falls+Of+Neuse+Rd+27609&format=json&key=ZZZZZZZZ
When I take the json results and put it into Json2CSharp, it renders fine. When I try and load it into a type provider:
type RestaurantListingJson = JsonProvider< #"http://pubapi.atti.com/search-api/search/devapi/search?term=Jumbo+China+5&searchloc=6108+Falls+Of+Neuse+Rd+27609&format=json&key=ZZZZZZZ">
I get a 400
Looking at fiddler, I see
"User agent is a required field"
Has anyone run into this before? How do I add a user agent to a type provider?
Thanks in advance
I have not created an account, so I could not try this - but if the error message says "user agent is a required field", then I guess that the service requires setting the User-Agent header of the HTTP request.
This is not supported in static parameters of the JsonProvider, so the best way to get this to work would be to download the sample JSON, save it to a local file (say yp.json) and then use that to create the type provider:
type Yp = JsonProvider<"yp.json">
To actually download some data (when you want to make a request), you can use Http.RequestString which takes headers - there you can specify any required headers including User-Agent:
let response =
Http.RequestString("http://httpbin.org/user-agent", headers=["user-agent", "test"])
Then you can load the data using Yp.Parse(response) (rather than using the Load method directly to request a URL which would not let you specify the header).
The latest version of F# Data now always sends user agent and accept headers, so this should now work directly:
type RestaurantListingJson = JsonProvider<"http://pubapi.atti.com/search-api/search/devapi/search?term=Jumbo+China+5&searchloc=6108+Falls+Of+Neuse+Rd+27609&format=json&key=ZZZZZZZ">

Google docs API: can't download a file, downloading documents works

I'm trying out http requests to download a pdf file from google docs using google document list API and OAuth 1.0. I'm not using any external api for oauth or google docs.
Following the documentation, I obtained download URL for the pdf which works fine when placed in a browser.
According to documentation I should send a request that looks like this:
GET https://doc-04-20-docs.googleusercontent.com/docs/secure/m7an0emtau/WJm12345/YzI2Y2ExYWVm?h=16655626&e=download&gd=true
However, the download URL has something funny going on with the paremeters, it looks like this:
https://doc-00-00-docs.googleusercontent.com/docs/securesc/5ud8e...tMzQ?h=15287211447292764666&amp\;e=download&amp\;gd=true
(in the url '&amp\;' is actually without '\' but I put it here in the post to avoid escaping it as '&').
So what is the case here; do I have 3 parameters h,e,gd or do I have one parameter h with value 15287211447292764666&ae=download&gd=true, or maybe I have the following 3 param-value pairs: h = 15287211447292764666, amp;e = download, amp;gd = true (which I think is the case and it seems like a bug)?
In order to form a proper http request I need to know exectly what are the parameters names and values, however the download URL I have is confusing. Moreover, if the params names are h,amp;e and amp;gd, is the request containing those params valid for obtaining file content (if not it seems like a bug).
I didn't have problems downloading and uploading documents (msword docs) and my scope for downloading a file is correct.
I experimented with different requests a lot. When I treat the 3 parameters (h,e,gd) separetaly I get Unauthorized 401. If I assume that I have only one parameter - h with value 15287211447292764666&ae=download&gd=true I get 500 Internal Server Error (google api states: 'An unexpected error has occurred in the API.','If the problem persists, please post in the forum.').
If I don't put any paremeters at all or I put 3 parameters -h,amp;e,amp;gd, I get 302 Found. I tried following the redirections sending more requests but I still couldn't get the actual pdf content. I also experimented in OAuth Playground and it seems it's not working as it's supposed to neither. Sending get request in OAuth with the download URL responds with 302 Found instead of responding with the PDF content.
What is going on here? How can I obtain the pdf content in a response? Please help.
I have experimented same issue with oAuth2 (error 401).
Solved by inserting the oAuth2 token in request header and not in URL.
I have replaced &access_token=<token> in the URL by setRequestHeader("Authorization", "Bearer <token>" )

Resources