문제

My code:

NSString *urlString = [NSString stringWithFormat:@"%@%@%@%@", @"http://api.search.live.net/json.aspx?Appid=am hiding the appid &query=",text,@"&sources=web&web.offset=",offvalue];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [NSData dataWithContentsOfURL:url];

The JSON response:

SearchResponse =     {
        Errors =         (
                        {
                Code = 1002;
                HelpUrl = "http://msdn.microsoft.com/en-us/library/dd251042.aspx";
                Message = "Parameter has invalid value.";
                Parameter = "SearchRequest.AppId";
                Value = " am hiding the value";
            }
        );
        Query =         {
            SearchTerms = iphone;
        };
        Version = "2.2";
    };
}

What wrong am I doing here.Can anyone please rectify my query??How to use version 2.2 of the bing API

도움이 되었습니까?

해결책

What is the value of 'text', is this one word or multiple words? You'll need to perform URL_Encode on the parameter 'text' in order to have a valid URL.

See Objective-C and Swift URL encoding Be sure only to have the URL_Encoding on the text-object and not on the whole URL, otherwise "http://" will be encoded as well, resulting in an invalid URL as well

Eg a space should be %20 , you can verify this by adding a NSLog of the URL

다른 팁

It looks like you entered the wrong AppID judging from.

Parameter = "SearchRequest.AppId";

Make sure that the AppID matches the appID that they assigned your app with the service.

Also (and this sometimes randomly causes issues for me) make sure you put a / at the end of the URL String.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top