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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器