Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Kareny

macrumors newbie
Original poster
Jun 21, 2010
22
0
Hi guys,
I am trying upload by clicking a button.
Is there any code between
-(IBAction)buttonClick: (id) sender

and

-(void)Upload

Thanks very much!
 
Post your current code and some details on your server setup and we can help you diagnose your problem.
 
Post your current code and some details on your server setup and we can help you diagnose your problem.

Thanks very much and here is my code:


Code:
@interface testingViewController : UIViewController 
<UIActionSheetDelegate> {
	IBOutlet UITextField *NameField;
	IBOutlet UIButton    *SUBMITButton;
	NSMutableData *webData;
}

@property (retain, nonatomic) UITextField *NameField;
@property (retain, nonatomic) UIButton * SUBMITButton;
-(IBAction)textFieldDoneEditing: (id)sender;
-(IBAction)SUBMITPressed: (id)sender;
@property (retain, nonatomic) NSMutableData *webData;
@end


#import "testingViewController.h"

@implementation testingViewController

@synthesize NameField;
@synthesize SUBMITButton;
@synthesize webData;
-(IBAction)textFieldDoneEditing: (id)sender
{
	[sender resignFirstResponder];
}
- (IBAction)SUBMITPressed: (id)sender {
			if (![sender isKindOfClass:[UIButton class]])
				return;}//really do not know what code should be
				
-(void)Upload
{
	NSString *soapMessage	= [NSString stringWithFormat:
								   @"<?xml version=\"1.0\"encoding=\"utf-8\"?>\n"
								   "soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"xmls:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
								   "<soap:Body>\n"
								   "<Upload xmlns=\"http://tempuri.org/\">\n"
								   "<name>%@</name>\n"
												
								   "</Upload>\n"
								   "</soap:Body>\n"
								   "</soap:Envelope>\n",NameField.text
								   ];
		
		
		NSURL *url = [NSURL URLWithString:@"http://10.11.10.91/vesupload/Service.asmx?wsdl"];
		NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
		NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMessage length]];
		
		[theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
		[theRequest addValue:@"http://10.11.10.91/vesupload/UploadImage" forHTTPHeaderField:@"SOAPAction"];
		[theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
		[theRequest setHTTPMethod:@"POST"];
		[theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
		
		
		NSURLConnection * theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
		
		if(theConnection)
		{
			webData = [[NSMutableData data]retain];
			
		}
		else {
			NSLog(@"theConnection is NULL");
		 }
}

The server set up is:
Code:
SOAPAction:"http://tempuri.org/Upload"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmls:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmls:soap="http://schemas.xmlsoap.org/soap/envelope/">\n"
								   "<soap:Body>\n"
								   "<Upload xmlns=\"http://tempuri.org/\">\n"
								   "<name>string</name>\n"
												
								   "</Upload>\n"
								   "</soap:Body>\n"
                                                                   "</soap:Envelop>\n"
 
If your code is supposed to upload when the submit button is tapped then your action method should look like

Code:
- (IBAction)SUBMITPressed: (id)sender {
     [self Upload];
}

which will start your POST.

Otherwise, tell us what you want to happen and what does happen.
 
If your code is supposed to upload when the submit button is tapped then your action method should look like

Code:
- (IBAction)SUBMITPressed: (id)sender {
     [self Upload];
}

which will start your POST.

Otherwise, tell us what you want to happen and what does happen.

Hi, thanks for the help, I want to press the SUBMIT button, then upload the 'name' on to my web server. I put the code in my file and also added
-(void)Upload;
into my interface file.

But still, there was 'name' on my server. Any idea about this?:)
BTW, the Xcode did not have any warnings when I pressed Build & Run.
 
NSURLConnection * theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
No, that's just where you set the delegate, not the delegate methods themselves (like, for example in this case, connection:didReceiveResponse:). If that doesn't make sense, I suggest stepping away from the real coding and going and (re)learning the basics of Objective-C.
 
No, that's just where you set the delegate, not the delegate methods themselves (like, for example in this case, connection:didReceiveResponse:). If that doesn't make sense, I suggest stepping away from the real coding and going and (re)learning the basics of Objective-C.

I got the code like this,but still not working.Is the code right?
Code:
#pragma mark NSURLConnection delegate methods
-(void)connection: (NSURLConnection *)connection didReceiveResponse: (NSURLResponse *)response
{
        [webData setLength: 0];
        NSLog(@"connection: didReceiveResponse:1");
}
-(void)connection: (NSURLConnection *)connection didReceiveData: (NSData *)data
{
        [webData appendData:data];
        NSLog(@"connection: didReceiveData:2");

}
-(void)connectionDidFinishLoading: (NSURLConnection *)connection
{
        NSLog(@"3 DONE. Received Bytes: %d", [webData length]);
        NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
        NSLog(theXML);
        [theXML release];
}
 
I got the code like this,but still not working.Is the code right?
The code seems to be right, but only insomuch as it encounters no problems, which obviously you are. Have you coded a connection:didFailWithError:? You say it's not working. Please elaborate? Are you getting run-time errors? How much of the NSLogs you've included are being executed?
 
The code seems to be right, but only insomuch as it encounters no problems, which obviously you are. Have you coded a connection:didFailWithError:? You say it's not working. Please elaborate? Are you getting run-time errors? How much of the NSLogs you've included are being executed?


Thanks again for reply!!
I have coded this:
Code:
-(void)connection: (NSURLConnection *)connection didFailWithError: (NSError *)error
{
NSLog(@"ERROR with theConnection"):
[connection release];
[webData release];
}

I do not have any errors or warnings after I click 'Bulid and Run'. The problem is I got nothing on my webservice. I want to send a 'name.text' on my webservice, but I got nothing.
 
I do not have any errors or warnings after I click 'Bulid and Run'. The problem is I got nothing on my webservice. I want to send a 'name.text' on my webservice, but I got nothing.
You should also check for errors in your connection:didReceiveResponse:'s NSHTTPURLResponse (see the SeismicXML sample app for how this might be done).

I didn't get an answer to this question: How much of the NSLogs you've included are being executed?

Also, the issue may exist on the server side. Is it receiving the SOAP request and responding appropriately?
 
You should also check for errors in your connection:didReceiveResponse:'s NSHTTPURLResponse (see the SeismicXML sample app for how this might be done).

I didn't get an answer to this question: How much of the NSLogs you've included are being executed?

Also, the issue may exist on the server side. Is it receiving the SOAP request and responding appropriately?


Thanks again for this.
I did learn the sample and check the NSHTTPURLResponse, there was still nothing.Also the server side was fine. It is receiving the SOAP request, as I have tested it already.

I think the problem was the NSLogs part, I don't think the NSLogs were executed.
 
You should also check for errors in your connection:didReceiveResponse:'s NSHTTPURLResponse (see the SeismicXML sample app for how this might be done).

I didn't get an answer to this question: How much of the NSLogs you've included are being executed?

Also, the issue may exist on the server side. Is it receiving the SOAP request and responding appropriately?

Hi dejo,
also I use the breakpoints, it stop at
NSURL *url = [NSURL URLWithString:mad:"http://10.11.10.91/vesupload/Service.asmx?wsdl"];
I think maybe the problem is about the conncetion,did I miss some code for the conncetion part?
 
also I use the breakpoints, it stop at
NSURL *url = [NSURL URLWithString:mad:"http://10.11.10.91/vesupload/Service.asmx?wsdl"];
Is that the line where you set the breakpoint? If so, then that's where it's supposed to stop.

I tried putting your code into a simple project (needed to add statics for NameField and webData) and I also am not getting any NSLog output. I tried putting breakpoints in all the NSURLConnection delegate methods and none of them are being triggered. This leads me to believe that the issue lies within the communication with the SOAP server. The NSURLConnection is being initialized fine but neither connection:didReceiveResponse: nor connection:didFailWithError: is being triggered. Also, I don't even get any response when trying to access http://10.11.10.91/ from a browser.
 
10.x.x.x is ipv4's private address space. It is never routed onto the internet.

http://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces

The OP might want to use the 'tcpdump' command or a GUI network-traffic watcher of some kind, to see what is happening on the actual network. He says the request appears on the server, but is the server sending a response? If not, then none of the requester's delegate methods will be called.

One might also use the 'curl' command to test the server's response to a known-good request.

Interarchy 8 has a traffic watcher. Interarchy 9 doesn't. I use 8, so I don't have any suggestions for a GUI traffic watcher.
 
To the OP:
Post your most recent code.

Your original code contains a number of bugs, which will cause nothing to happen. You said you've made changes, but we need to see the actual code resulting from those changes. As it now stands, we're all debugging what you told us about your code; we're not debugging your actual code.

You should also copy and paste the actual data received by the server. I don't believe you did this before. I surmise this because there is a typo, </soap:Envelop> instead of </soap:Envelop>, which appears in what you said is your server setup, but which doesn't appear in the source code you posted.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.