views:

37

answers:

1

Hello guys. I'm trying to upload a file onto my personal server.

I've written a small php page that works flawlessy so far.

The little weird thing is the fact that I generate all the body of the HTTP message I'm going to send (let's say that amounts to ~4 mb) and then I send the request to my server.

The server, then, asks for an HTTP challenge and my delegate connection:didReceiveAuthenticationChallenge:challenge replies to the server with the proper credentials and the data.

But, what's happened? The data has been sent twice!

In fact I've noticed that when I added the progressbar.. the apps sends the data (4mb), the server asks for authentication, the apps re-sends the data with the authentication (another 4mb). So, at the end, I've sent 8mb. That's wrong.

I started googling and searching for a solution but I can't figure out how to fix this.

The case scenarios are two (my guess):

  • Share the realm for the whole session (a minimal HTTP request, then challenge, then data)
  • Use the synchronized way to perform an HTTP connection (things that I do not want to do since it seems an ugly way to handle this kind of stuff to me)

Thank you

+1  A: 

You've run into a flaw into the http protocol: you have to send all the data before getting the response with the auth challenge (when you send a request with no credentials). You can try doing a small round trip as the first request in the same session (as you've mentioned), like a HEAD request, then future requests will share the same nonce.

Kylar
Is there a way to do that using the NS stuff provided by iPhone SDK?I managed to achieve the goal using ASIHTTPRequest and doing two connections (the first synchronized, with username and password) and the second one asynchronized filled only with the data.It's just a matter of curiosity but I'd like to dig into this.
Fabiano Francesconi
Can you not use NSUrlConnection? If not, you might be stuck with CFNetwork directly, or (as you've already used) ASIHttpRequest. (I'm not a iPhone programmer, so I'm giving you advice based on my Mac experience, old as it is.)
Kylar