network-programmingpostmanalamofirealamofire-requestpostman-native-app

HTTP-GET method returns a different result in browser versus POSTMAN desktop app?


I'm building an iOS app and I need to run an HTTP request and process the response body.

The problem is that my request-url is not giving the same response body when I test it out in Postman / Alamofire (swift) versus Browser / Postman-chrome-extenstion. I need to know why!?

This is the url:

https://www.google.com/search?tbs=sbi:AMhZZivGExkvmpguEZhe42DkT_1rMlcib7qBIztMPGfETwnezLiPyUSkqWXCvkcNvYoMmGZUT6OZrP27vhKRuaEWMFjjIQNdxDTmtkHYapxOICPAwLiP7BF6CRWnP-AGa5-Skoqjt6yKiQ8NGSJTJs5tADelkjneEVMDLMMbg6OuEhxorXiOpFlKX5kr3NDb6z8MAbdjkGGkJdEAzfvloCgJiojx6FeKlyy1fLAYns5faQjLlUjRYoD0nErpyoDaiKrlIVr4VQF_18KFxxm4xnX2UNQmLvHvaBUT3xbYofqMS49r2Yp0wJRVCLSc-rIzRCZscc8CnV4hHv

When tested in browser it gives me a google-search-result with visually similar images.

When tested in POSTMAN or in my swift code it returns a default blank google screen.

Any help much appreciated!


Solution

  • Try setting the User-Agent and Accept Headers to the same thing your browser sends. As an example Opera will send these headers:

    User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36 OPR/62.0.3331.99
    
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
    

    Adding those headers in postman allowed me to get the same result as the browser.