dsigh7478 2015-08-27 09:21
浏览 104

如果请求从移动应用程序发送到PHP,应该相当于HTTP_USER_AGENT?

I want to pass an URL to some function in PHP. My concern is related to the value of server variable $_SERVER['HTTP_USER_AGENT']

Actually when I made a request from the browser the respective function works fine but when I made a request from CURL or iOS mobile app it gives following data, in both these cases the function doesn't perform well. I want the exactly equivalent value in these two requests likerequest made from browser.

Following are the three outputs/responses of (echo $_SERVER['HTTP_USER_AGENT'];)from the three different requests:

Response when request made from Mozilla Firefox:

Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0

Response when request made from CURL(Terminal on Ubuntu Linux):

curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3

Response when request made from iOS app :

Campusknot/31 (iPhone Simulator; iOS 8.3; Scale/2.00)

Please help me in order to work the function from iOS app as well as from CURL, from web browser it is working fine now, so no new issues with the request made from web. Thanks in advance.

  • 写回答

1条回答 默认 最新

  • duandi5328 2015-08-27 09:43
    关注

    One of the option is just to specify the User Agent string, i.e - curl:

    curl -A "Desired User Agent String" google.com
    

    and for iOS:

    NSMutableURLRequest *request = ...;
    [request setValue:@"Desired User Agent String" forHTTPHeaderField:@"User-Agent"];
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用三极管设计—个共射极放大电路
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示