gpt4 book ai didi

iphone - 使用 initWithContentsOfUrl 时如何设置内容类型

转载 作者:太空狗 更新时间:2023-10-30 03:31:57 25 4
gpt4 key购买 nike

基本上我要设置

内容类型:application/json;

为了调用 dot net web 服务并将 json 返回给 iphone 应用程序。

目前我有

NSString * jsonres = [[NSString alloc] initWithContentsOfURL:url];

我需要什么来发出阻止请求?

最佳答案

你需要使用 NSURLMutableRequest,在这里你可以为内容类型和排序添加标题,这里是引用,http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSMutableURLRequest_Class/Reference/Reference.html#//apple_ref/occ/cl/NSMutableURLRequest ,一旦你设置了你的请求,你就可以使用这种方法添加值 - (void)addValue:(NSString *)value forHTTPHeaderField:(NSString *)field something like

[request setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];

关于iphone - 使用 initWithContentsOfUrl 时如何设置内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1323817/

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