bryan
bryan

Reputation: 9389

Sending User Agent header through URLFetch API on GAE

I'm sending a request to my API like so:

$context = stream_context_create(
    array(
        'ssl' => array('verify_peer' => false,  'allow_self_signed' => true),
        'http' => array('method' => 'GET', 'header'  => "Authorization:Basic " . base64_encode($token.':'))
    )
);
$resp = file_get_contents('https://api.site.com/test', false, $context);

if(!preg_match("/200 OK/", $http_response_header[0]))   http_response_code(400);
else                                                    echo $resp;

However, I am trying to let api.site.com to know what my HTTP_USER_AGENT is that's making the request.

What's the best way to accomplish this?

Upvotes: 1

Views: 260

Answers (1)

Josh J
Josh J

Reputation: 6893

Add the User-Agent header along side your Authorization:Basic in the stream context options under the http key. See http://php.net/manual/en/context.http.php for details

Edit: Google App engine information

Headers identifying request source

The following headers indicate the app ID of the requesting app:

  • User-Agent. This header can be modified but App Engine will append an identifier string to allow servers to identify App Engine requests. The appended string has the format "AppEngine-Google; (+http://code.google.com/appengine; appid: APPID)", where APPID is your app's identifier.

  • X-Appengine-Inbound-Appid. This header cannot be modified, and is added automatically if the request is sent via the URL Fetch service when the follow redirects parameter is set to False.

Upvotes: 2

Related Questions