• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Post method - NSMutableURLRequest
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Post method - NSMutableURLRequest


  • Subject: Post method - NSMutableURLRequest
  • From: Matic <email@hidden>
  • Date: Sun, 19 Jul 2009 11:40:19 +0200

Hello,

I am trying to get information from a website with post method but I cannot
get the right content. This is the website. I should get the bus schedule
which is displayed after you enter number in the field on the first page.HTML
Code:

 http://wbus.talktrack.com/

. Here is the code of the website:Code:

<html><body>
<form id="Form1" name="Form1" method="post" action="wap.aspx?__ufps=666968">
<input type="hidden" name="__EVENTTARGET" value="">
<input type="hidden" name="__EVENTARGUMENT" value="">
<script language=javascript><!--
function __doPostBack(target, argument){
  var theform = document.Form1
  theform.__EVENTTARGET.value = target
  theform.__EVENTARGUMENT.value = argument
  theform.submit()
}
// -->
</script>
<div align="Center"><img src="img/waplogo.gif" alt="LPP" border="0" /><br>
LPP - Napoved prihodov avtobusov.<br>
Vnesite ime postaje<br>
<input name="tb_postaja"/><br>
<input name="b_send" type="submit" value="Prikaži"/><br>
<a href="wap.aspx?culture=sl-SI">slo</a>
                |
                <a
href="wap.aspx?culture=en-GB">eng</a></div></form></body></html>

When you enter the number into the field you should get the bus schedule.

Here is my code:Code:

NSString *post = @"tb_postaja=163";
	NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding
allowLossyConversion:NO];
	NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

	NSMutableURLRequest *urlRequest = [[[NSMutableURLRequest alloc] init]
autorelease];
	NSString *testString =@"http://wbus.talktrack.com/";;
	//testString = [testString stringByAppendingString:string2];
	[urlRequest setURL:[NSURL URLWithString:testString]];
	[urlRequest setHTTPMethod:@"POST"];
	[urlRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
	[urlRequest setValue:@"application/x-www-form-urlencoded"
forHTTPHeaderField:@"Content-Type"];
	[urlRequest setHTTPBody:postData];
	NSData *urlData;
	NSURLResponse *response;
	NSError *error;

	urlData = [NSURLConnection sendSynchronousRequest:urlRequest
returningResponse:&response error:&error];


	NSLog(@"Succeeded! Received %d bytes of data",[urlData length]);
    NSString *aStr = [[NSString alloc] initWithData:urlData
encoding:NSASCIIStringEncoding];
    NSLog(aStr);

.

Thanks in advance.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: NSPasteboard and data types
  • Next by Date: [iPhone] CFAttributedStringRef autorelease - not possible?
  • Previous by thread: Core Data, NSArraycontrollers and secondary to-many relationships.
  • Next by thread: [iPhone] CFAttributedStringRef autorelease - not possible?
  • Index(es):
    • Date
    • Thread