我正在尝试编写应用程序以将我的日程安排加载到我的iOS日历中。 但我有问题通过代码将我的用户传递发送到服务器。 地址是:
http://78.39.179.41/delivery.dll
这是网页的主体:
<html><head><title>Crew Delivery</title><style> body.bodydef {font-family: Tahoma; text-decoration: none; BACKGROUND-COLOR: #fdfff4; color: #000000; font-size: 9pt } input.def {text-transform: uppercase; font-family: Tahoma} </style></head><body class="bodydef" style="font-family: Tahoma">Welcome to crew scheduling delivery system <form Name="Schedule Request" method="POST" action=""> Crew Code : <input id="Text1" maxlength="4" name="Code" title="Code" style="width: 129px; text-transform: uppercase;" type="text" /><br /><br /> Crew Pass :   <input id="Text2" maxlength="4" name="Pass" title="Pass" style="width: 129px" type="password" /> <br /><br /> Table Type: <Select id="TableType" label="Select Table Type" Name="TableType"> <option>Brief</option> <option>Detail</option> </Select>  <br /><br />     <input id="Channel" Name="Channel" type="hidden" value="D2FB680ADAE641889F8B4159FA23F7C4"/> <input id="Submit1" style="width: 69px" type="submit" value="submit"/>     <input id="Reset1" style="width: 65px" type="reset" value="reset"/> </form></body></html>
&#13;
我试图通过以下方式实现:
NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://78.39.179.41/delivery.dll"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[theRequest setHTTPMethod:@"POST"];
NSString *postString = [NSString stringWithFormat:@"username=%@&password=%@"];
[theRequest setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
但我不知道我的* postString应该是什么字符串。
答案 0 :(得分:3)
试试这个 -
NSURL *url = [NSURL URLWithString:@"http://78.39.179.41/delivery.dll"];
NSString *code = @"userx";
NSString *pass = @"xxxxx";
NSString *tableType = @"Brief"; //Brief or Detail
NSString *channel = @"655F23D118A847D9BD0544E0583677E7"; //some unique number generated by server
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[request setHTTPMethod:@"POST"];
NSString *postString = [NSString stringWithFormat:@"Code=%@&Pass=%@&TableType=%@&Channel=%@", username, password, tableType, channel];
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *connection= [[NSURLConnection alloc] initWithRequest:request delegate:self];
在此代码中,我们在postString
中发送帖子变量,我们使用的所有变量都是html中的表单元素。看到这个 -
<form Name="Schedule Request" method="POST" action="">
Crew Code :
<input id="Text1" maxlength="4" name="Code" title="Code" style="width: 129px; text-transform: uppercase;" type="text" />
Crew Pass :
<input id="Text2" maxlength="4" name="Pass" title="Pass" style="width: 129px" type="password" />
Table Type:
<Select id="TableType" label="Select Table Type" Name="TableType">
<option>Brief</option>
<option>Detail</option>
</Select>
<input id="Channel" Name="Channel" type="hidden" value="AB46BD275DA94020BEE071FEB971B6B9"/>
<input id="Submit1" style="width: 69px" type="submit" value="submit"/>
<input id="Reset1" style="width: 65px" type="reset" value="reset"/>
</form>
这是你的html表单,其中输入和选择标签有主要信息,其中name是post变量的关键,value是post字符串的post值。我们使用
分隔变量&安培;
示例 -
代码= codevalue&安培;传= XXXX&安培;类型=任何