1

I saw these post, but they did not work out:

You can find the entire code here :https://github.com/te2020/GoEuroAPiClassLibrary/blob/master/GOEuroApi_Requests.cs

Only the relevant part of it(what I think):

httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
            httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Encoding", "gzip, deflate");
            httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0");

            httpClient.BaseAddress = new Uri("https://www.goeuro.com/");


            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "/GoEuroAPI/rest/api/v5/searches");
            request.Content = new StringContent(jsonString,
                                                Encoding.UTF8,
                                                "application/json");//CONTENT-TYPE header

My fiddler looks like this and it works.

I get the eror after sending that request:

 var response = await httpClient.SendAsync(request);

What did I miss ?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Jane Kins
  • 43
  • 1
  • 6
  • I'm getting errors too, also from Fiddler and Postman - are you sure their API is running OK? – Jim W Jan 31 '17 at 05:22
  • yes, a few days ago the same logic worked, but my fiddler still works – Jane Kins Jan 31 '17 at 12:03
  • I uploaded for you the export of my fiddler(composer= , please take a look http://en.file-upload.net/download-12279292/fiddlerExport_Composer.raz.html – Jane Kins Jan 31 '17 at 12:09

1 Answers1

1

If you use HTTP for your request (instead of HTTPS), you can see a more helpful response from the server:

{"message":"Search options are not correct!","statusCode":400}

This would seem to indicate that the searchOptions JSON you're sending is invalid for some reason. Without knowing the goeuro API it's impossible for me to say what the exact problem is. Unfortunately I don't have time to probe it.

What I would do though is use the Fiddler 'compare' tool to compare your working request against the request coming from your program. Just select both requests in Fiddler and right click -> compare. Then try to make your request exactly the same as the working one. I notice there are cookies in the working request that you probably aren't sending, you should add those.

Jim W
  • 4,866
  • 1
  • 27
  • 43
  • even by removing `https` to `http` worked, but this is strange I used `https` some time ago and it worked ... – Jane Kins Jan 31 '17 at 17:31
  • I'd talk to goeuro.com because when I was playing I was getting 500 errors from them, which means something happened they didn't handle, which isn't good really... so maybe they have problems right now – Jim W Jan 31 '17 at 17:32