iOS 上的 http GET
我试图通过 HTTP GET 请求从 PC 上的服务获取答案(图像)。 如果我将请求放入网络浏览器,我会得到请求的图像。如果我尝试在 iPhone 应用程序中获取它,它不起作用。
请求是:
http://192.168.151.82:54000/snapshot?s=<snapshotrequest xmlns=\"http://www.vizrt.com/snapshotrequest\"><videomoderequest><width>880</width><height>495</height></videomoderequest><snapshotdata view=\"all\"/></snapshotrequest>&p=http://192.168.151.82:8580/element_collection/storage/shows/%%257B3646FFAC-4E77-41AB-BDFC-F581D157ABA3%%257D/elements/1000/
我的获取代码是:
NSString *str = [NSString stringWithFormat: @"http://192.168.151.82:54000/snapshot?s=<snapshotrequest xmlns=\"http://www.vizrt.com/snapshotrequest\"><videomoderequest><width>880</width><height>495</height></videomoderequest><snapshotdata view=\"all\"/></snapshotrequest>&p=http://192.168.151.82:8580/element_collection/storage/shows/%%257B3646FFAC-4E77-41AB-BDFC-F581D157ABA3%%257D/elements/1000/"];
NSURL *url = [[NSURL alloc] initWithString:str];
UIImage *img = [ [ UIImage alloc ] initWithData: [ NSData dataWithContentsOfURL: url ] ];
您可以看到,处理了引号和百分号等特殊字符。 我用wireshark在PC上观看网络通信,但没有任何通信。
Im trying to get answer (an image) from a service on a PC with a HTTP GET request.
If I put the request into a webbrowser, I get the requested image. If I try to get it in iPhone app, it doesnt work.
the request is:
http://192.168.151.82:54000/snapshot?s=<snapshotrequest xmlns=\"http://www.vizrt.com/snapshotrequest\"><videomoderequest><width>880</width><height>495</height></videomoderequest><snapshotdata view=\"all\"/></snapshotrequest>&p=http://192.168.151.82:8580/element_collection/storage/shows/%%257B3646FFAC-4E77-41AB-BDFC-F581D157ABA3%%257D/elements/1000/
my code for getting is:
NSString *str = [NSString stringWithFormat: @"http://192.168.151.82:54000/snapshot?s=<snapshotrequest xmlns=\"http://www.vizrt.com/snapshotrequest\"><videomoderequest><width>880</width><height>495</height></videomoderequest><snapshotdata view=\"all\"/></snapshotrequest>&p=http://192.168.151.82:8580/element_collection/storage/shows/%%257B3646FFAC-4E77-41AB-BDFC-F581D157ABA3%%257D/elements/1000/"];
NSURL *url = [[NSURL alloc] initWithString:str];
UIImage *img = [ [ UIImage alloc ] initWithData: [ NSData dataWithContentsOfURL: url ] ];
You can see, that speciel characters like quotes and percentes are handeled.
Im watching network communication on the PC with wireshark and there isn't any communication.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在从参数创建 url 之前,您需要对参数进行 url 编码,
并确保您的 iPhone 与您的计算机位于同一 wifi 上,因为您使用的是本地 IP 地址
You need to url encode your parameters before creating a url from them
And also make sure your iPhone is on same wifi as your computer as you are using local IP address