Farhad
Farhad

Reputation: 33

Send User & Pass to a webpage by iOS

i'm trying to write an app to load my schedule into my iOS calendar. but i have problem sending my user pass to the server by code. the address is:

http://78.39.179.41/delivery.dll

and this is the body of webpage:

<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>

i Tried to do it by below way:

 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]];

but i don't know what string my *postString Should be.

Upvotes: 0

Views: 49

Answers (1)

Dinesh Kumar Vyas
Dinesh Kumar Vyas

Reputation: 482

Try this out -

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];

In this code we send post variables in postString and all variable we are using are form elements in html. see this -

<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>

This is your html form in which input and select tags having main information where name is key of post variable and value is post value for the post string. we separate variables using

&

example -

code=codevalue&pass=xxxx&type=any

Upvotes: 3

Related Questions