ios - 通过 iOS 将用户和密码发送到网页

标签 ios asp.net objective-c http

我正在尝试编写一个应用程序来将我的日程安排加载到我的 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 : &nbsp;<input id="Text1" maxlength="4" name="Code"    title="Code" style="width: 129px; text-transform: uppercase;" type="text" /><br /><br /> Crew Pass : &nbsp &nbsp;<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>&nbsp <br /><br />&nbsp&nbsp&nbsp&nbsp <input id="Channel" Name="Channel" type="hidden" value="D2FB680ADAE641889F8B4159FA23F7C4"/> <input id="Submit1" style="width: 69px" type="submit" value="submit"/> &nbsp&nbsp&nbsp&nbsp<input id="Reset1" style="width: 65px" type="reset" value="reset"/> </form></body></html>

我尝试通过以下方式做到这一点:

 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 应该是什么字符串。

最佳答案

试试这个 -

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 中发送了 post 变量,我们使用的所有变量都是 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 表单,其中输入和选择标签具有主要信息,其中名称是发布变量的键,值是发布字符串的发布值。我们使用

分隔变量

&

例子-

code=codevalue&pass=xxxx&type=any

关于ios - 通过 iOS 将用户和密码发送到网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34220559/

相关文章:

iOS-charts 带有负值的条形图

c# - 列表框滚动条在没有任何命令的情况下移动

c# - Excel 下载过程在 ASP.NET 中的大型数据集的情况下死于页面

objective-c - 如何将光标位置向前移动特定长度?

iphone - 找不到 PDF 标题 : '%PDF' not found

ios - SwiftUI:NavigationView 内 TabBar 内的 ListView 生成空 View

iOS:如何使用整数值对 TableView 进行排序但想要显示字符串值?

c# - 按钮不起作用的 CountClick 方法

objective-c - 是否可以将 block 定义为类的成员?

ios - textFieldShouldEndEditing 故障?