Tag: http get

如何在JavaScript中查询iTunessearchAPI?

我试图查询应用程序商店的信息给定的应用程序,但是我不断收到以下错误。 XMLHttpRequest cannot load https://itunes.apple.com/lookup?id=<some-app-id>. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.<some-website>.co.uk' is therefore not allowed access. The response had HTTP status code 501. 我用来执行请求的代码如下。 有谁知道我可能会出错? var config = { headers: { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET', 'Access-Control-Allow-Headers': 'Content-Type, X-Requested-With', } }; $http.get("https://itunes.apple.com/lookup?id=<some-app-id>", config).success( function(data) { // I got some data back! […]

URL编码iOS NSURL错误

在Firefox中打开的URL,桌面上的Chrome浏览器,在iPhone上的WebView中不打开。 这个URL据说是访问一个GET请求。 当创buildNSURL没有percentescaping的url不会得到生成。 当使用percentescape时,url会redirect到一个Bad url内容。 在桌面浏览器上使用不同的编码,而不是在iPhone上使用? 或移动Safari? 有没有不同的方式来编码在iOS中的URL,而不是使用 -stringByAddingPercentEscapesUsingEncoding -CFURLCreateStringByAddingPercentEscapes 从服务器生成不好的请求内容页面。 任何帮助将是非常好的,谢谢。 编辑: 生成的URL如下 http://something.test.com/iostest/index.html?{"a":"b"} pipe理认为,不编码大括号是造成iOS中的问题。 如在 NSString *tempUrlSting = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)tempURLA,CFSTR("{}"), CFSTR("\""), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding))); NSURL *tempUrl=[NSURL URLWithString:tempUrlSting]; 如果不是在URL中对大括号进行编码,而是使用[Rob's answer] [1]对其余的进行编码,如上所述。 创buildNSURL时,url是空的。 如果对大括号进行编码,则生成的URL很好,但服务器会引发exception。 这个问题build议使用CFNetworking。 编辑 使用CFNetworking如下 -(void)getDataFromUrl{ CFStringRef tempURLA = CFSTR("http://my.test.server/iostest/index.html?{\"a\":\"b\"}"); CFStringRef tempUrlSting = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)tempURLA,CFSTR("{}"), CFSTR("\""), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)); CFURLRef myURL = CFURLCreateWithString(kCFAllocatorDefault, tempUrlSting, NULL); CFStringRef […]