ios post html代码,在IOS上发送HTTP POST请求

在IOS上发送HTTP POST请求

我正在尝试用我正在开发的iOS应用程序发送HTTPPost,但是推送永远不会到达服务器,尽管我确实获得了响应代码200(来自urlConnection)。我从来没有得到服务器的响应,服务器也没有检测到我的帖子(服务器确实检测到来自Android的帖子)

我确实使用ARC,但已经将PD和urlConnection设置为强连接。

这是我发送请求的代码NSMutableURLRequest *request = [[NSMutableURLRequest alloc]

initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",dk.baseURL,@"daantest"]]];

[request setHTTPMethod:@"POST"];

[request setValue:@"text/xml"

forHTTPHeaderField:@"Content-type"];

NSString *sendString = @"Item 1Item 2";

[request setValue:[NSString stringWithFormat:@"%d", [sendString length]] forHTTPHeaderField:@"Content-length"];

[request setHTTPBody:[sendString dataUsingEncoding:NSUTF8StringEncoding]];

PushDelegate *pushd = [[PushDelegate alloc] init];

pd = pushd;

urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:pd];

[urlConnection start];

这是我的委托代码#import "PushDelegate.h"@implementation PushDelegate@synthesize data;-(id) init{

if(self = [super init])

{

data = [[NSMutableData alloc]init];

[data setLength:0];

}

return self;}- (void)connection:(NSURLConnection *)connection didWriteData:(long long)bytesWritten totalBytesWritten:

(long long)totalBytesWritten{

NSLog(@"didwriteData push");}- (void)connectionDidResumeDownloading:(NSURLConnection *)connection totalBytesWritten:(long long)

totalBytesWritten expectedTotalBytes:(long long)expectedTotalBytes{

NSLog(@"connectionDidResumeDownloading push");}- (void)connectionDidFinishDownloading:(NSURLConnection *)connection destination

URL:(NSURL *)destinationURL{

NSLog(@"didfinish push @push %@",data);}- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWri

tten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite{

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值