1

I have a project that uses wxCurl to retrieve a file over HTTP. However, if the server sends a 301 or 302, all I get back is an empty string. I heard there was a way to get cURL to follow the location: headers sent by the server. How is this done?

Also, how do you set the User-agent header in wxCurl?

Nathan Osman
  • 71,149
  • 71
  • 256
  • 361

2 Answers2

0

Call mywxCurlHttpObject->SetOpt(CURLOPT_FOLLOWLOCATION, 1);

that will set the underlaying libCurl option correctly.

I don't know about the user agent -- you'd have to set that in the header in libCURL, but I don't see a way to set those with the wxCURL wrapper

RyanWilcox
  • 13,890
  • 1
  • 36
  • 60
  • Thanks for the example, but it didn't work - some deep searching in the source revealed nothing. I finally just used libCURL directly. – Nathan Osman Feb 01 '10 at 00:57
0

When you call wxCurlHTTP::Get() wxCurl overrites all settings you've done so far in wxCurlBase::SetCurlHandleToDefaults()...

In wxCurlHTTP::Get() your can add the line SetOpt(CURLOPT_FOLLOWLOCATION, 1); after the method is calling SetCurlHandleToDefaults() or you just inherit the method in a new class and add it there.

I've tried it with my RSS import tool written in wxWidgets & wxCurl. It worked!

CoolBeans
  • 20,654
  • 10
  • 86
  • 101
DirkMausF
  • 715
  • 5
  • 14
  • To change the User-agent add: SetOpt(CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); or whatever you want to set... – DirkMausF Sep 25 '11 at 21:51