gpt4 book ai didi

iphone - iOS 上的 http GET

转载 作者:行者123 更新时间:2023-11-29 04:47:45 25 4
gpt4 key购买 nike

我试图通过 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上观看网络通信,但没有任何通信。

最佳答案

在从参数创建 url 之前,您需要对参数进行 url 编码

NSString * unencodeParameter = @"<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 * encodedParameter = (NSString *)CFURLCreateStringByAddingPercentEscapes(
NULL,
(CFStringRef)unencodedParameter,
NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8 );

NSString *str = [NSString stringWithFormat: @"http://192.168.151.82:54000/snapshot?s=%@",encodedParameter];
NSURL *url = [[NSURL alloc] initWithString:str];
UIImage *img = [ [ UIImage alloc ] initWithData: [ NSData dataWithContentsOfURL: url ] ];

并且还要确保您的 iPhone 与您的计算机使用相同的 wifi,因为您使用的是本地 IP 地址

关于iphone - iOS 上的 http GET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9361989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com