0

I want to set proxy with Username and password for AFNetworking.
Below Is my code:

proxyDict = @{
@"HTTPEnable"  : [NSNumber numberWithInt:1],
                  (NSString *)kCFNetworkProxiesHTTPProxy  : proxyHost,
                  (NSString *)kCFNetworkProxiesHTTPPort  : proxyPortFormted,
                  };

NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
    sessionConfiguration.connectionProxyDictionary = proxyDict;

 NSMutableURLRequest *mutableRequest = [NSMutableURLRequest requestWithURL:URL];
[mutableRequest addValue:@"header Name" forHTTPHeaderField:@"header Value"];

After Adding this I am getting:

"Request failed: unacceptable content-type: text/html"

For this problem. I add this line.

 manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes                           setByAddingObject:@"text/html"];

After Adding the above line. I am getting this error.

"JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.,

But its working correctly

 curl --proxy proxyIP:proxyPort -U headerName:headerPassword.

Please help

Kampai
  • 22,848
  • 21
  • 95
  • 95
sunil
  • 70
  • 8
  • check this url http://stackoverflow.com/questions/28101582/how-to-programmatically-add-a-proxy-to-an-nsurlsession – Lalit kumar Apr 10 '17 at 07:03
  • Hi Lalit Kumar I have check with this, but it is not working again. Any other solution from your side. (NSString *)kCFProxyUsernameKey : userName, (NSString *)kCFProxyPasswordKey : passwrod, – sunil Apr 10 '17 at 07:14
  • manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"]; please check this is added or not – Lalit kumar Apr 10 '17 at 07:18
  • Hi I have check this previously I checked again Its the same problem. "Request failed: unacceptable content-type: text/html" – sunil Apr 10 '17 at 07:30
  • Check this all self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil]; – Lalit kumar Apr 10 '17 at 07:34
  • After adding that. I am getting this error now. "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set" – sunil Apr 10 '17 at 07:38

0 Answers0