I want to show the Progress from a Download.
I want to load an Document and show it in an Webview.
Everything is working, only my progress(the - (void)setProgress:(float)newProgress method) shows up 4 times and says value: 0.000000.
Even the -(void)request:(ASIHTTPRequest *)request didReceiveBytes:(long long)bytes method jumps from received bytes 1 then to its original size.
What Iam doing wrong?
The Server sends me an Response Header:
{
"Cache-Control" = "private,max-age=0";
"Content-Length" = 22993;
"Content-Type" = "application/vnd.ms-word.document.12";
Date = "Tue, 28 Feb 2012 12:20:18 GMT";
Etag = "\"{EA1043C4-BE59-4775-AAC0-D25141572D94},2\"";
Expires = "Mon, 13 Feb 2012 12:20:18 GMT";
"Last-Modified" = "Wed, 13 Apr 2011 11:04:06 GMT";
MicrosoftSharePointTeamServices = "14.0.0.4762";
"Persistent-Auth" = true;
"Public-Extension" = "http://schemas.microsoft.com/repl-2";
ResourceTag = "rt:EA1043C4-BE59-4775-AAC0-D25141572D94#00000000002";
SPRequestGuid = "e4791157-4b6f-4961-84e1-2979d23bf5bc";
Server = "Microsoft-IIS/7.5";
"Set-Cookie" = "WSS_KeepSessionAuthenticated={d2e7fd96-aad9-429d-b85d-64a13026c693}; path=/, WSS_KeepSessionAuthenticated={d2e7fd96-aad9-429d-b85d-64a13026c693}; path=/, WSS_KeepSessionAuthenticated={d2e7fd96-aad9-429d-b85d-64a13026c693}; path=/";
"X-Content-Type-Options" = nosniff;
"X-Powered-By" = "ASP.NET";
"X-SharePointHealthScore" = 0;
}
ASIHTTPRequest *asiRequestTemp = [ASIHTTPRequest requestWithURL:[NSURL URLWithString: self.documentURL]];
[asiRequestTemp setTimeOutSeconds:10];
[self setAsiRequestDocumentViewer:asiRequestTemp];
[asiRequestDocumentViewer setDelegate:self];
[asiRequestDocumentViewer setUseKeychainPersistence:YES];
[asiRequestDocumentViewer setUseSessionPersistence:YES];
[asiRequestDocumentViewer setShowAccurateProgress:YES];
[asiRequestDocumentViewer setDownloadProgressDelegate:self];
[asiRequestDocumentViewer setDownloadDestinationPath:mediaPath];
[asiRequestDocumentViewer startAsynchronous];
Whats wrong with that, even the Content Length is shown up!
I experienced a similar problem. How large is the data you're downloading? Have you checked how it's coming in? ASIHTTPRequest does't start updating your progress download until it has successfully downloaded your headers, and I've noticed that if the data is small enough to come in in two or three bursts, setProgress will be called only with a value of 0.0 and 1.0.
Related
I'm writing an HTTP server and client in python. When I run my scripts for client and server in terminal everything works fine. However, when I go to my browser and type "localhost:12000" in the searchbar, I get an error saying "The page isn't working. localhost didn't send any data. ERR_EMPTY_RESPONSE". What I expect to see instead, is the content of the html file contained in the response message.
This is the code for my HTTP client.
from socket import *
clientSocket = socket(AF_INET,SOCK_STREAM)
serverPort = 18000
clientSocket.connect(("localhost",serverPort))
request = "GET www.somepage/index.html HTTP/1.0\r\nHost: www.somepage.com\r\nConnection: close\r\nUser-Agent: Chrome/86.0.4240.183\r\nAccept: text/html, application/xhtml+xml\r\nAccept-Language: it-IT, en-US\r\nAccept-Encoding: gzip, deflate\r\nAccept-Charset: ISO-8859-1, utf-8\r\n"
print(request)
clientSocket.send(request.encode())
response = (clientSocket.recv(1024)).decode()
print(response)
clientSocket.close()
This is the code for my server.
from socket import *
from datetime import date
from time import gmtime, strftime
import calendar
serverSocket = socket(AF_INET,SOCK_STREAM)
serverPort = 12000
serverSocket.bind(("localhost",serverPort))
serverSocket.listen(1)
current_date = calendar.day_abbr[date.today().weekday()]+", "+date.today().strftime("%d %b %Y")+strftime(" %H:%M:%S", gmtime())+ " GMT"
while True:
connection , addr = serverSocket.accept()
request = (connection.recv(1024)).decode()
request = request.split()
method = request[0]
URL = request[1]
version = request[2]
if method == "GET" and URL == "www.somepage/index.html" and version == "HTTP/1.0":
response = "HTTP/1.0 200 OK\r\nConnection: close\r\nDate: {}\r\nServer: Apache\r\nLast-Modified: Tue, 10 Nov 2020, 6:31:00 GMT\r\nContent-Length: 72 bytes\r\nContent-Type: text/html\r\n<html>\r\n<title>PAGE TITLE</title>\r\n<body>\rThis is the body\r\n</body></html>".format(current_date)
connection.send(response.encode())
connection.close()
So the server is checking if the request line is correct and then sending the HTTP response, which I do see in the terminal, but when I try in the browser I get an error instead. I've also tried checking Wireshark and I do see the HTTP messages there, so I don't understand why my browsers says no data has been sent.
Thank you all for your help.
Edit:
I couldn't post my code in the comment so I'll try here. What I'm trying to do is create an HTTP client and server than don't implement the entire HTTP protocol, but just a few request methods and a few replies. For now I was starting with the GET method and the 200 OK reply.
This is the code for my client. I have added an extra \r\n at the end of the header in the request.
from socket import *
clientSocket = socket(AF_INET,SOCK_STREAM)
serverPort = 12000
clientSocket.connect(("localhost",serverPort))
request = "GET /index.html HTTP/1.0 \r\nHost: www.somepage.com\r\nConnection: close\r\nUser-Agent: Chrome/86.0.4240.183\r\nAccept: text/html, application/xhtml+xml\r\nAccept-Language: it-IT, en-US\r\nAccept-Encoding: gzip, deflate\r\nAccept-Charset: ISO-8859-1, utf-8\r\n\r\n"
print(request)
clientSocket.send(request.encode())
response = (clientSocket.recv(1024)).decode()
print(response)
clientSocket.close()
This is the code for my server, with an added \r\n at the end of header as well.
from socket import *
from datetime import date
from time import gmtime, strftime
import calendar
serverSocket = socket(AF_INET,SOCK_STREAM)
serverPort = 12000
serverSocket.bind(("localhost",serverPort))
serverSocket.listen(1)
current_date = calendar.day_abbr[date.today().weekday()]+", "+date.today().strftime("%d %b %Y")+strftime(" %H:%M:%S", gmtime())+ " GMT"
while True:
connection , addr = serverSocket.accept()
request = (connection.recv(1024)).decode()
request = request.split()
method = request[0]
URI = request[1]
version = request[2]
host = request[4]
if method == "GET" and URI == "/index.html" and version == "HTTP/1.0" and host == "www.somepage.com":
response = "HTTP/1.0 200 OK \r\nConnection: close\r\nDate: {}\r\nServer: Apache\r\nLast-Modified: Tue, 10 Nov 2020, 6:31:00 GMT\r\nContent-Length: 83 bytes\r\nContent-Type: text/html\r\n\r\n<html>\r\n<title>PAGE TITLE</title>\r\n<body>\rThis is the body\r\n</body></html>".format(current_date)
connection.send(response.encode())
connection.close()
I've studied the standard and I'm trying to write my code according to the specifications. What I see in my browser is this error:
error
I've also noticed that if I change my server code to this:
from socket import *
from datetime import date
from time import gmtime, strftime
import calendar
serverSocket = socket(AF_INET,SOCK_STREAM)
serverPort = 12000
serverSocket.bind(("localhost",serverPort))
serverSocket.listen(1)
current_date = calendar.day_abbr[date.today().weekday()]+", "+date.today().strftime("%d %b %Y")+strftime(" %H:%M:%S", gmtime())+ " GMT"
while True:
connection , addr = serverSocket.accept()
request = (connection.recv(1024)).decode()
request = request.split()
method = request[0]
URI = request[1]
version = request[2]
host = request[4]
if "GET" in request:
response = "HTTP/1.0 200 OK \r\nConnection: close\r\nDate: {}\r\nServer: Apache\r\nLast-Modified: Tue, 10 Nov 2020, 6:31:00 GMT\r\nContent-Length: 83 bytes\r\nContent-Type: text/html\r\n\r\n<html>\r\n<title>PAGE TITLE</title>\r\n<body>\rThis is the body\r\n</body></html>".format(current_date)
connection.send(response.encode())
connection.close()
where basically the only difference is the way the if statement is written, then my browser will display correctly the html, that is, I see this:
page
So it seems the problem lies in the syntax I used for my python code, and not the way the standard is implemented?
Thank you again so very much for your help.
I couldn't post my code in the comment so I'll try here. What I'm trying to do is create an HTTP client and server than don't implement the entire HTTP protocol, but just a few request methods and a few replies. For now I was starting with the GET method and the 200 OK reply.
This is the code for my client. I have added an extra \r\n at the end of the header in the request.
from socket import *
clientSocket = socket(AF_INET,SOCK_STREAM)
serverPort = 12000
clientSocket.connect(("localhost",serverPort))
request = "GET /index.html HTTP/1.0 \r\nHost: www.somepage.com\r\nConnection: close\r\nUser-Agent: Chrome/86.0.4240.183\r\nAccept: text/html, application/xhtml+xml\r\nAccept-Language: it-IT, en-US\r\nAccept-Encoding: gzip, deflate\r\nAccept-Charset: ISO-8859-1, utf-8\r\n\r\n"
print(request)
clientSocket.send(request.encode())
response = (clientSocket.recv(1024)).decode()
print(response)
clientSocket.close()
This is the code for my server, with an added \r\n at the end of header as well.
from socket import *
from datetime import date
from time import gmtime, strftime
import calendar
serverSocket = socket(AF_INET,SOCK_STREAM)
serverPort = 12000
serverSocket.bind(("localhost",serverPort))
serverSocket.listen(1)
current_date = calendar.day_abbr[date.today().weekday()]+", "+date.today().strftime("%d %b %Y")+strftime(" %H:%M:%S", gmtime())+ " GMT"
while True:
connection , addr = serverSocket.accept()
request = (connection.recv(1024)).decode()
request = request.split()
method = request[0]
URI = request[1]
version = request[2]
host = request[4]
if method == "GET" and URI == "/index.html" and version == "HTTP/1.0" and host == "www.somepage.com":
response = "HTTP/1.0 200 OK \r\nConnection: close\r\nDate: {}\r\nServer: Apache\r\nLast-Modified: Tue, 10 Nov 2020, 6:31:00 GMT\r\nContent-Length: 83 bytes\r\nContent-Type: text/html\r\n\r\n<html>\r\n<title>PAGE TITLE</title>\r\n<body>\rThis is the body\r\n</body></html>".format(current_date)
connection.send(response.encode())
connection.close()
I've studied the standard and I'm trying to write my code according to the specifications. What I see in my browser is this error:
error
I've also noticed that if I change my server code to this:
from socket import *
from datetime import date
from time import gmtime, strftime
import calendar
serverSocket = socket(AF_INET,SOCK_STREAM)
serverPort = 12000
serverSocket.bind(("localhost",serverPort))
serverSocket.listen(1)
current_date = calendar.day_abbr[date.today().weekday()]+", "+date.today().strftime("%d %b %Y")+strftime(" %H:%M:%S", gmtime())+ " GMT"
while True:
connection , addr = serverSocket.accept()
request = (connection.recv(1024)).decode()
request = request.split()
method = request[0]
URI = request[1]
version = request[2]
host = request[4]
if "GET" in request:
response = "HTTP/1.0 200 OK \r\nConnection: close\r\nDate: {}\r\nServer: Apache\r\nLast-Modified: Tue, 10 Nov 2020, 6:31:00 GMT\r\nContent-Length: 83 bytes\r\nContent-Type: text/html\r\n\r\n<html>\r\n<title>PAGE TITLE</title>\r\n<body>\rThis is the body\r\n</body></html>".format(current_date)
connection.send(response.encode())
connection.close()
where basically the only difference is the way the if statement is written, then my browser will display correctly the html, that is, I see this:
page
So it seems the problem lies in the syntax I used for my python code, and not the way the standard is implemented?
Thank you again so very much for your help.
request = "GET www.somepage/index.html HTTP/1.0\r\nHost: www.somepage.com\r\nConnection: close\r\nUser-Agent: Chrome/86.0.4240.183\r\nAccept: text/html, application/xhtml+xml\r\nAccept-Language: it-IT, en-US\r\nAccept-Encoding: gzip, deflate\r\nAccept-Charset: ISO-8859-1, utf-8\r\n"
This is not a valid HTTP request. First, it should only contain the path /index.html and not domain/path as you currently do. It is also missing the final \r\n at the end which signals the end of the HTTP header.
In the same way the expectations of the server wrong too, which explains why it causes problems when faced with a client correctly implementing HTTP (the browser). Additionally the HTTP response is also missing the final \r\n after the HTTP header and the Content-length: 72 does not match the actual length of the content.
Please don't implement HTTP by (wrongly) second-guessing how it works. There is an actual standard for this and implementations are expected to follow this standard.
After the edit the code looks like this:
request = request.split()
...
version = request[2]
host = request[4]
if method == "GET" and URI == "/index.html" and version == "HTTP/1.0" and host == "www.somepage.com":
... send response ...
There are multiple problems here: the first one is that the browser will not use HTTP/1.0 as version but HTTP/1.1.
The next problem is that the domain might not be in the variable host since it is might not be in request[4]. It is blindly assumed that the Host header is in the second line of the request since it is implemented like this in the client. But the HTTP standard does in now way require this. And while it might be the case with some clients it is not the case with others. Instead of blindly assuming that something is in a specific place in the HTTP header the header should actually be parsed properly to extract the Host header.
I'm trying to write an iphone app the download video fromyou tube. I take feeds with gdata api but i think the url in the feed is not the ur of the video but the url of the html page. This is my code:
-(void)downloadSongWithURL:(NSURL*)songURL andDelagate:(PlayViewController*)dataReceiver{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:songURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:15];
toSendData = dataReceiver;
connectionYouTube = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
[connectionYouTube start];
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
dataReceived = [[NSMutableData alloc] init];
NSLog(#"receive response function: %#", response);
}
-(void)connection:(NSURLConnection*)connection didFailWithError:(NSError *)error{
connection = nil;
NSLog(#"Connessione fallita");
}
-(NSCachedURLResponse *)connection:(NSURLConnection *)connection
willCacheResponse:(NSCachedURLResponse*)cachedResponse{
return nil;
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[dataReceived appendData:data];
NSLog(#"receiv data function: %# Connection: %#", data, connection);
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
[toSendData receivedData:dataReceived];
NSLog(#"dataaaaaaaaaaaa: %#", [NSString stringWithUTF8String:[dataReceived bytes]]);
NSLog(#"download finish connection: %#", connection);
}
that log me this:
2014-04-11 16:55:23.039 AudioTube[5572:70b] receive response function: <NSHTTPURLResponse: 0xf780d70> { URL: https://www.youtube.com/v/Ek0SgwWmF9w?version=3&f=videos&app=youtube_gdata } { status code: 200, headers {
"Alternate-Protocol" = "443:quic";
"Cache-Control" = "no-store";
"Content-Length" = 4411;
"Content-Type" = "application/x-shockwave-flash";
Date = "Fri, 11 Apr 2014 14:55:22 GMT";
Expires = "Tue, 27 Apr 1971 19:44:06 EST";
P3P = "CP=\"This is not a P3P policy! See http://support.google.com/accounts/bin/answer.py?answer=151657&hl=en for more info.\"";
Server = "gwiseguy/2.0";
"Set-Cookie" = "YSC=uT7YqaOWRV8; path=/; domain=.youtube.com; httponly, GEUP=8386b307efd185ab8f2e9d0d7d782d69aTAAAAA=; path=/; domain=.youtube.com; expires=Sun, 10-Apr-2016 14:55:22 GMT";
"X-Content-Type-Options" = nosniff;
"X-Frame-Options" = ALLOWALL;
"X-XSS-Protection" = "1; mode=block; report=https://www.google.com/appserve/security-bugs/log/youtube";
} }
2014-04-11 16:55:23.041 AudioTube[5572:70b] receiv data function: <43575311 471e0000 78dab539 69731bc9 75dd3303 f40c4010 07499002 49093c24 1e3b0440 52074951 5a5114c1 6329820b 50ab6305 01436000 421a1c8b 1990e2ae 3796956c 761d3b1b 3b4e9838 8e633a87 e364936c 8ecae77c cb67502a 4b1f53e5 aaa4fc2f 98d73d03 1294bc2a 6faa42a1 a7e7bdee 7ef77b3d dd7a8c84 5f22d4fa 33845a30 bae19510 426ff325 0ea1bd6e 8494ed7c aaaa1885 521ea1f3 a1a98b93 93172f9c 9f9c9ebe 847af71c 0869d9ca 4384c628 d4899051 303415a1 9b355d0d 8e056f2a d992aaeb 300424f5 1d84c643 11005a80 6876bb90 55cb8001 d88fd076 41dd4965 cab59201 4ca6ce8f 4f4f4d4d c2880f66 6a5a79c7 124037e7 b722a46a d08a9b6a 36ab6601 2302795d 3347e711 2ad4aa5a 51795c55 61c19661 54f49970 b8301eda 350ac57c 28532e86 b70be185 4791447e e776313a bd1336e7 66d59c52 d38cd0c3 4ade5486 89982a64 116a9a6c 6a5d30b5 9e02e82a 552d77cc 486fe2b3 6be86118 dc2c94c2 154dd955 ab63db39 6d455bcb 4c3c0a67 2a7a882e ecddeb00 2baaa5bc b195d2d5 4cb99405 a92727a8 a13c0df5 99aaa67a ef239453 1f57109a 8e5c8a5c 88c8d313 972e46ce d36e3a72 419e3e7f 2132c1ba a9f17179 7afce245 da4d5e3a 3f7e09a0 c9f39374 e6e4e4c4 14202fc2 3074e723 13130c9a a0169f36 adf79bd9 6deb8393 36bb6c2e d6b3bfd9 723d7b62 39fa4f09 ad63883d 7f2b3cd7 53a97525 f348c9ab 7a2893df ad25d6d1 61eb191b 0caf7f96 c443c8c2 a5f25a79 53d150a5 5a36cac6 6e454545 a550425a 59c9ce6b 850acab0 4755550c 75a15831 766f9621 d4d8c8d1 db2acc55 ab1092d9 79b0f626 30456a49 d9d4d487 ba522980 d1739aa2 6f21f5b1 a1564bc0 6ac17a59 2e419f53 322aa488 52d0e80a a454f3b5 a25a3274 942b2155 cf282050 56d58d6a 7917d54a 542ac616 55d56279 5b3d16c6 8c0e2649 1615f4f5 66900649 18e915ad 6030b3ce 58c6454d 91866860 a14229ab 3e8ee510 8b2b10da 58b61010 6b48af6d 821c348d 53d4c1e1 306a8426 9a4b2454 63bd5aae 44350592 6c8f4322 eaf1f97e cca12f79 0ae01e86 fa1cd20c 21fe143c 3e050fc5 f6042420 915b0300 779a00ff 39242746 2d7dc8b4 fc3d1e82 58140875 2b741ced 6c8c9a3d 3ebb4710 a1144572 0d48709d 146d0e8a 9fb75032 3c90013b be44c723 d21a7d3a 9657a974 a7105be3 64232d6c c4c59ead 6b74f827 96c45c1f 8a3112ee 9e3d1b22 3ca0d68e 41ee2488 4f828881 20a8702c baa7277e d5149820 816353e6 4d3c9dc8 54352de6 8d5304e5 f76b6414 e39db163 bd7c96a8 23e8223a b28b600e c53b5fc1 b4bd8669 3f26065e e8b0a126 d2fe23d2 ae264376 ac5d6d9a d3499dc8 77429d16 bb4c0d1a 78fa3c15 875181a9 2b981601 d8c65c6e 1303cb3e e60c07b2 10ddcb3e 13a64b03 e64cb692 b356dad9 44bbd863 4e0c62ca b6f775b6 a7295bc2 843af315 a3e25789 1c8c379c b908d324 16277df0 e660b210 72087f79 cafd2cda 73024290 9a83d3a4 d11f670b 7ec8410d a0abc4e3 5541b64a 7cc3aa26 b94c170d 58a63c8a 3998e6b4 4c36b808 6382933e c5b3ecdd c1decf2c 9a6ee118 11e0c8b3 a502270a d4e16e53 434ec066 909dbbd2 091bf70d 78fdec34 64e3cd8d b9c47cea e6dcf21a 32b60a7a a364b202 c9129a66 71a795e0 8dc8e598 b07c9c52 fa774a69 113cb955 d60d3403 55c82a43 bbe59a51 db5443f9 7239afa9 50257556 84465162 5737d422 827dac56 2d18bbe6 f675a36c b2ec0496 22b6d898 1d4fdcd0 f53305e3 27b21140 09d991f5 b7366b16 2516b1cb d4030144 2d6c37c9 10b36ab0 8512887e c3f32b7e 16cd5362 f71cd434 9410cf6d bbd189bf 5f3940ea 94a944ca d229a554 40c50c7c 6f944ba9 c44e0eca e2e35df4 1fedffdd 4e2b12d4 a3aa5254 c7910785 28857f85 bcd82e17 b22d6c8f 08a9dbb4 f6db1668 e758a856 cb55f66a 4fb0c22b 466ba50c a54bae97 cb60b692 d35c5533 0a9a2e5d df35d4b9 6a55d9b5 68e9cc94 2e73779a 2fc366f3 d8b0c736 1faa19e3 34886dd9 3ed47045 93d86243 6c974929 5bd0e9fe 624f54c0 27ead09b 17cf3416 dbcd3da9 0bf6c5c6 8ec79459 2d805c25 b5ea2a97 e68eb7cc 9672c994 74b95430 9ce6feb9 a2cf550a f67289a2 dce5d209 2a6d4d64 1b34ec1a a3e06912 9099c691 5072aa49 ddd560c3 8cdb562e c5d50f6a b0bfae2b d42d404e b79be3dd af129939 2622513e d4dcfae9 d7f6f204 8d5cf576 152ca256 c3af1179 f3fc53e0 5fa596df 328e5dbf a494b29a 5af5af2e 2cceada6 5612a9e8 adb5f98d e5d85a6a 6deee682 3daee617 1e579c4d df1ed2d1 c7849857 8df714ad a676ea6a 29bb0e01 74bb606c 81c7e26a 4ead56d5 aa033430 54b652ca 6ca99947 6b6003a7 ae80b90b 1f422ce5 bd2cfd12 996aa162 cc6532f0 29ee6a8c b2558e0c 3ca2c04e cdb66be5 529ee298 e896d402 1d171356 32e35167 533ab7b1 f7e5124b 75d5c439 342b0472 6547e5c8 23cea6af a93ef601 130e2bd9 32841dfd 269c4b4c 86272291 8be1cd5a 41838ffc f613313b 63c6ece0 49e40db3 379381a6 06f056ab 674e4e62 2e5220df b6557362 f71b88f4 34e7ef0c f31c1d57 0cb06b15 8ff3f0a5 e4a111db 9c00c2f2 daf2868d e58a3743 f313868e f46f598e 1d0781b8 1c4b2dc4 e3b1b8af 61cbe3b1 d6c4c2fc adf8f2c6 5d73468b bea55455 9391de32 77e3466a 7e6e75f5 fadcfc3b e2c29d8d 85f8dadc aa2fbef0 eead85c4 466a7d2e 0e3104c8 84648a5f 520dc7ad f8aa9513 02f586eb 0447acda 988a2d39 ab12d188 2119adac 830f5d59 4b63c65c c82a86e2 38668165 1babfd22 8dd5ad82 96f56c29 fa097b10 4871caa4 1506623b 25fa3da9 568d5d89 71dc804f 73079c0a e7958a01 bcdcaf> Connection: <NSURLConnection: 0xf76a380> { request: <NSMutableURLRequest: 0xf77b830> { URL: https://www.youtube.com/v/Ek0SgwWmF9w?version=3&f=videos&app=youtube_gdata } }
2014-04-11 16:55:23.056 AudioTube[5572:70b] receiv data function: <98d875c2 1bded77c e7fff52e 6f7b3de1 f45702c8 aa1b2726 7a1fbcaf 8c7d3837 762f3236 9d0a0d26 df1a6cb5 fc6fa5b7 f7b53cb7 15f43565 cda6d2e5 76f3b466 a35573b7 a361cae0 f048f0a3 605505f5 4a41fe72 f063d770 63888e84 b6956ab0 c0768fe0 9560b69c 61e78490 7534d154 0a0d0f99 1386462e 9f36df42 bab10bc5 c7520616 0e95ca25 75e8f254 63b89ab9 32f4104a 86ce927c a69f7a6d 866e15e1 2da3a8c9 b39be5ec eed55938 2504e9d4 fb4376f3 50e2ba3f 747536cc 06fb872e f71f8943 31743780 82c39c3c 6cf219b9 cc7d3c42 ebd146a1 a8566dcc 8881d76c 14a4e522 6894833e 78941f05 95202d2a 4138a3a8 213b1cb0 e1a427d2 2994085f 801083d3 926e637b 9ea41b4a 9551e772 25e9a848 092560ce ddbf8ff3 a4aa8205 322affcb 273fc7c1 0e10e5dd 9aa21572 05a864e0 3a9d953e c84238e2 d43206f8 68ad0667 e6aaad48 e36b6459 d3d4bca2 05bf42e4 c6a92d38 c40d851c c7171eae 13f71d9c aa898d3b 07815e7b 7063976c ecc2a3f5 e47d07a7 eff0e3a1 08afeb9a e3f82ae2 c2ffe926 426c5c42 389ba609 05c67d8a 58d728ad 27af0ff8 c98988b3 e9e240a0 170689ff 87fb0281 6a37feb5 6f0a1cc7 b73d62e3 b2e7cad7 bd3ed9a1 8e4d29fa 243decda cd6b87f1 af7debe0 3a71bdf4 6d7cec7b 59d564ea 64997958 d6776470 a77cec4e b9e11899 3a43b63c 219ff484 dce40599 7a811190 8ff507ba 39d9145e 3e214ad0 8ffdbc5f f23bfdad 7e4f97cf dfd3d5d7 351818b4 21faafb3 55bc1cf0 05660357 0257036f 07ae055c fe18c3f7 04fa0279 ff43786f 75e1569b db43bcbe b6f60e7f 67eb29ec 0988dd52 4f2f03b1 28b538f1 19b1dbe3 e8fc06c1 1ce1e074 6623183e a709c122 e11d4468 21d8456c 6e62f712 d246483b 211d84f8 09e924a4 8b905384 0408e926 706e23a7 093943ec 4182fb89 3840f059 e23c47f0 10c1c304 8f103c4a f05bc429 133c4670 88e03069 8910e738 c113044f 12e13cc1 1709be44 f014c1d3 d20cee86 f3c10d82 e709bf40 7094708b 042f116e 99e01582 df215deb 04bf4b70 9ce00471 6f48b7b0 f41eccbf 2dddc1d2 fb589a86 f7fb0427 89fb3de2 be453c29 e24e13b7 42b84d62 cf107b96 d85529c7 49f39cd4 cb93d38f 082e760b 049788a7 4cf036e1 3f24f823 d2fd5ba4 fb9b043f 0152df82 f61493ee df86f63b d03e81f6 bb9878be 0da7adef 62e9f7b1 403c7f80 a5019e78 ff1013ef 1f41db83 f6a7d0fe 0cda9f43 fb31b49f 40fb29b4 bf82f6d7 d07e06ed 6fa1fd1d b42fa05d 27de7f82 ee9fa1dd ed65c712 386660cc 218e3ed0 6b0f1ece 502d2d1c 166cd60c 1e0b821d 39b0c3d1 7cb6e130 11d9cc23 8c9d3576 7e84530b 25255878 09618b9e 24015e10 9ae8f00e a7481076 b6d065d8 0547db56 3892bae1 14ef81a5 0e871723 ce07f4da e0300e47 a40ee4a7 677638f4 77740131 173ed587 5a0392e4 40dd08b5 15ec48f8 01c60fa1 fb638c1f 41f72718 6bd0fd10 e322743f c2b804dd 1c2ec3f3 2f30ae40 b78ff107 d0fd25c6 5536a4c3 f36f3036 185083e7 cf31de86 eeef31de 81ee1f30 7e0cdd3f 62bc0bdd 97187fc8 267e04cf 7fc1b805 77236c43 1e578f1d f7a2d35e a9eb8c8f f706bdf6 f63e2fe9 e847bc1d 0d789d81 41afe3d4 599fe03b e715fd43 08ac3b8c 381b1af1 dada7827 7680f9dc b84340b8 070704c4 f5822545 89af4716 c1763c27 39eed623 f565941e 952fc4de c2ac9371 3d3d960b e5c2f2dc 17a3f47e 7d24ab61 792617d9 def2d4e9 ebf55c64 aba52ecf d773ae58 1b971e4b 73b9f17a ce1b9be0 92932b93 e8c9e42f 82d016e9 595f70b8 7f84eb91 dba32f22 2a3e28e2 7ab263a5 036db5d7 73edb9f3 e63a37ac 33c10bb9 8bf59cff 08bc949b 6a0273d3 f26a3dd7 da04deac e77c4de0 5a3dd769 82c9997a ae656506 27c5a115 11c72e73 9e0e84ea 9167917b 68f4e568 e4ad224e fa637ed4 2bf28bb8 f82dfc09 9ebd82af 4254215e 00838c82 4192d241 54c2b9b7 adfe9af2 3a0a3407 0d05baa2 a31e49ce 25396be4 7a94c3b1 390c8336 c1263936 ea91e027 2fa8d9ee e622be79 8406d14b 0b92ef45 e7f1d38c e0e94748 da149e0f b079cf60 9a17218b da8d6726 4a894c08 bcf7e5e1 a12880d8 10cc1c30 7602e305 5038b640 d911eace 00a0a2f2 836814fb 2009402c 5e7eb0c2 5b0289bc cde19ea1 ee7869ba 43c5cf8a 60318f0f 24480754 ac0146e3 62a7398f 975aec39 b5584660 26eb1585 45dc3938 3c7b05f4 86f85a82 d44392c0 391c7de9 407ae940 be135dc6 3ed791e0 d79f7a20 7b834f63 23d44e0e e0dcd24f 39678426 d62a7e5e e4931394 f135099c b788f825 881ab442 89bf0301 ee7038a1 6e8803f5 888ad252 24bd1a49 df8ca4d7 22e95824 ed84df1d d4cbfeb6 1c8bf4ff 838e42db 65c39223 6c867677 f08bbd51 1f8de3e4 b29c0329 b77d3e2a 669d8ab9 2e6fa5bb 87060f63 ef0ab0ac 15f39243 0413ceae cc221e21 b7c53c19 7f957917 fcee608b 79072cf5 f098175c f5c8839e 74af5cb8 8eb77a00 e9e500e9 ad47d289 dc99ed51 1f94aa91 f4d0de12 423e9e17 a44bd41e bf88a4fb 7dc02a7d 66294de7 30394764 2d3a82b7 973c1eea 8603ea86 179617b8 a125ecee 3b3bbb81 da6c4064 1e889ff1 524b2f1d 0ca2e400 3c72b7a2 0358b935 886b2f3c a0a874f0 2c3978f0 0cb08380 7df6fdda 8b6707b9 f73afee7 f0307d2e 7810bdcd 8138ed02 c70beda0 e739b902 3460fdbe fcc17ef4 1c86b10e 1b8c0db3 b1aaacef cbc6be5c db4f0e26 ef1c44ef 60a0b92f efeccb8f f7e5ddfd d8391a64 7e9b2048 3f384afa bea745c1 7278f26e f42ed2a9 d7c11e23 e904753b f087099e c02b09fa 60e89c32 a4721ae6 214b1ff4 9f53faad e5343e7f aa1779e8 f9b3df5b fb72d467 a7461d06 1ffbbac0 abc3c97b f2372861 6a877df9 e3fd957b 38364cc3 5a58c2dd 63e3b31b c2fb743f b98ff824 7a80700a a5119744 9d02d42a 577230ad 3093805a a079170f 7bd5c4ab e902e686 3d6f51c5 d73a9fd8 8a7c3a91 1c608a0c 50263ce4 0e04b142 336413f1 3694a191 7cca66e7 854f39a8 044fa417 c14f5e1e 04db99c7 3c1f51f7 a453ffe6 13117a0f 3d913c20 d92de861 da20ca08 074f3336 6a1a69d3 b6299cfe e4e5b3e4 c073e003 ee7c6eb9 73c22678 ff0b8a82 4d149e2d 49074b92 94140ea2 028618fc 14cb9fe1 eb1cf4d1 2c07f0ef 59f07728 bce4d906 63a907b9 5c54c519 417e8a37 85809d16 27cf0242 b2cb82b0 e712409f 370639cf 3080a205 f15434d9 6e418207 ea8d87be d968e20f 8244ddc6 e1a1edec e121fc2a eca71f1e 020aa100 0f21d50b 819dee89 e6b10fa6 1f2c2567 e5efe183 7df9fb78 7f6516be 1b50376c f9363b4b 6188aa1e c844de0d 51b84533 51bac3f5 6e05002d b7d16bce 375f1286 8e2e46af c1dcff05 9255a543> Connection: <NSURLConnection: 0xf76a380> { request: <NSMutableURLRequest: 0xf77b830> { URL: https://www.youtube.com/v/Ek0SgwWmF9w?version=3&f=videos&app=youtube_gdata } }
2014-04-11 16:55:23.058 AudioTube[5572:70b] dataaaaaaaaaaaa: CWSG
2014-04-11 16:55:23.059 AudioTube[5572:70b] download finish connection: <NSURLConnection: 0xf76a380> { request: <NSMutableURLRequest: 0xf77b830> { URL: https://www.youtube.com/v/Ek0SgwWmF9w? version=3&f=videos&app=youtube_gdata } }
i don't think that this data log is the data byte of the video.
So this is the way that i have the feed from youtube:
GDataEntryBase *entry = (GDataFeedYouTubeVideo *)aFeed; //aFeed sarebbe un feed restituitomi da youtube
GDataMediaContent *flashContent = [LDConnecting mediaContentOfEntry:entry];
NSString *tempURL = [flashContent URLString];
I do it in the right way?
The url type of feed (https://www.youtube.com/v/Ek0SgwWmF9w? version=3&f=videos&app=youtube_gdata) is right?
Where am I wrong?
I look so long for this question and at the end i solv it! The html youtube page encode links to files of the song in url_encoded_fmt_stream_map so you must decide thet to have the link. In my case i was looking for the smallest videofile and my code do this. So i post it for help other people...
-(NSString*)directLinkToVodeoOfYouTubePage:(NSString*)html{
if(!html) return nil;
html = [html stringByReplacingOccurrencesOfString:#"\\u0026" withString:#"&"];
NSArray *split = [html componentsSeparatedByString:#"\""];
int i;
for(i=0;i<[split count];i++){
NSString *current = [split objectAtIndex:i];
if([current isEqualToString:#"url_encoded_fmt_stream_map"]){
html = [split objectAtIndex:i+2];
}
}
split = [html componentsSeparatedByString:#","];
for(NSString *current in split){
if([current rangeOfString:#"quality=small"].location != NSNotFound) html = current; //here get my quality video
}
html = [[[html stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
html = [[html componentsSeparatedByString:#"url="] objectAtIndex:1];
html = [[html componentsSeparatedByString:#";+codecs="] objectAtIndex:0];
split = [html componentsSeparatedByString:#"&itag="];
if([split count] > 2){
html = [NSString stringWithFormat:#"%#&itag=%#", [split objectAtIndex:0], [split objectAtIndex:1]];
}
return html;
}
Of course this code is deprecabile because of google changes, and some video like vevo have different encoded_stream_maps. But this is what i was able to do.
I am currently updating my app to .json from xml for Twitters new API v1.1. I currently have .json working and can log on, get me timelines, mentions, but when trying to get direct messages, lists, or user info it seems its looking for "cookies" but it is not stored.
This is the error message received by twitter when trying to make a simple GET user/show call:
Twitter request failed: 08AD12D3-0044-49AB-8D3D-4E61D8398550 with error:Error Domain=HTTP
Code=400 "The operation couldn’t be completed. (HTTP error 400.)" UserInfo=0xce90540
{response=<NSHTTPURLResponse: 0xce94bd0> { URL:
https://api.twitter.com/1.1/users/show.json?screen_name=FreeAppl3 } { status code: 400,
headers {
"Content-Encoding" = gzip;
"Content-Type" = "application/json; charset=utf-8";
Date = "Fri, 14 Jun 2013 09:25:40 UTC";
Server = tfe;
"Set-Cookie" = "guest_id=v1%3A137120194019582695; Domain=.twitter.com; Path=/;
Expires=Sun, 14-Jun-2015 09:25:40 UTC";
"Strict-Transport-Security" = "max-age=631138519";
"Transfer-Encoding" = Identity;
} }, body={"errors":[{"message":"Bad Authentication data","code":215}]}hjD4nzoeOUaTQ1Q%3D}
When I call [twitterEngine isAuthorized]; is returns YES and if I check for my access token string, I receive what was stored on initial login. I have searched and searched as to what is happening or how to fix the issues, but am simply stuck and any help would be greatly appreciated.
Twitter API - https://dev.twitter.com/docs/api/1.1/get/users/show
Twitter Error Codes - https://dev.twitter.com/docs/error-codes-responses
refer FHSTwitterEngine you can use newly FHSTwitterEngine and if you request this method without autenticating, the users status is removed... you need to send consumer key and token along with screen_name..
In FHSTwitterEngine
//get username pass to method. In Dictionary you can get all info
NSString *username = [[FHSTwitterEngine sharedEngine]loggedInUsername];
NSDictionary *data=[[FHSTwitterEngine sharedEngine]getUserProfile:username];
// method to get all user info
-(id)getUserProfile:(NSString *)username
{
if (username.length == 0) {
return getBadRequestError();
}
NSURL *baseURL = [NSURL URLWithString:url_users_show];
OAMutableURLRequest *request = [OAMutableURLRequest requestWithURL:baseURL consumer:self.consumer token:self.accessToken];
OARequestParameter *usernameP = [OARequestParameter requestParameterWithName:#"screen_name" value:username];
NSArray *params = [NSArray arrayWithObjects:usernameP, nil];
id userShowReturn = [self sendGETRequest:request withParameters:params];
return userShowReturn;
}
I'm using a firefox tool call "Poster" to check that my web service is working. When I POST the request I send a JSON object in the content to send (also call HTTP body data).
When I press the POST button the result is fine.
Now I want to do exactly the same with RestKit in objective-c:
NSString *squery = #"{\"Sort\":\"Relevance\",\"DaysToSearch\":0,\"WorkType\":\"\",\"PageSize\":20,\"LastRunCount\":0,\"IndustryCodes\":[\"\"],\"AccountId\":27,\"Experience\":\"\",\"GetResultCount\":0,\"Keywords\":\"iOS\",\"PageIndex\":0,\"DistanceFromLocation\":\"250\",\"SalaryType\":\"\",\"JobQueryId\":\"\",\"JobTitleCodes\":[\"\"]}";
RKObjectLoader *objectLoader = [[RKObjectManager sharedManager] objectLoaderWithResourcePath:url delegate:performJobQueryHandler];
objectLoader.method = RKRequestMethodPOST;
objectLoader.objectMapping = s.jobQueryDataMapper;
objectLoader.HTTPBody = [squery dataUsingEncoding:NSUTF8StringEncoding];
objectLoader.serializationMIMEType = RKMIMETypeJSON;
[objectLoader send];
As a result I get: "An non-fault exception is occured."
In the FireFox extension "Poster" if I use a different mine-type than "application/json", let say "application/x-www-form-urlencoded" I get the same error: "An non-fault exception is occured."
Is something wrong with objectLoader.serializationMIMEType = RKMIMETypeJSON; ???
Martin Magakian
Ok I think I find out.
I activated RestKit debug with
RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);
And I get:
2012-02-14 11:55:48 [4048:207] T restkit.network:RKRequest.m:318 Prepared POST URLRequest '<NSMutableURLRequest http://servicestest.foo.com/jobservice/jobservice.svc/json/jobquery>'. HTTP Headers: {
Accept = "application/json";
"Content-Type" = "application/x-www-form-urlencoded";
}. HTTP Body: Sort=Relevance&DaysToSearch=0&WorkType=&SalaryType=&LastRunCount=0&IndustryCodes[]=&Experience=&AccountId=0&GetResultCount=0&PageIndex=0&DistanceFromLocation=250&PageSize=20&JobQueryId=&JobTitleCodes[]=.
So I think using RKObjectLoader object don't care about objectLoader.serializationMIMEType = RKMIMETypeJSON; because the Content-Type remain "Content-Type" = "application/x-www-form-urlencoded"; instead of "Content-Type" = "application/json";
Do you think it's a bug or the normal behavior ?
I am using ASIHTTPRequest to contact an API the problem is that it is returning html instead of JSON and i have no idea why. Everything has been working great for weeks and i can't seem to figure out what has broken..
What's strange is doing exactly the same request with a browser or postie returns the correct JSON response, but when i do the request via ASIHTTPRequest these are the response headers i get:
"Cache-Control" = "private, max-age=0, must-revalidate";
Connection = "keep-alive";
"Content-Encoding" = gzip;
"Content-Type" = "text/html; charset=utf-8";
Date = "Tue, 05 Jul 2011 21:11:10 GMT";
Etag = "\"e467792713ac4124f055c1719f4ea6c2\"";
Server = "nginx/0.7.65";
Status = "200 OK";
"Transfer-Encoding" = Identity;
"X-Runtime" = 1;
And the html (which should be json)..
<div id="universal_meta" logged_in_user_id="removed" style="display:none"></div>
<div id="meta" screen="projects" logged_in_as="removed"></div>
<h1>9 projects with 50 open issues</h1>
<ul class="biglinks progressbars">
etc...
Here is the code used to do the request..
NSURL *url = [NSURL URLWithString:path];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
if(secure){
[request setUsername:self.username];
[request setPassword:self.password];
}
[request setDelegate:self];
[request setDidFinishSelector:#selector(requestDone:)];
[request setDidFailSelector:#selector(requestWentWrong:)];
[request setDownloadDestinationPath:destination];
[[self queue] addOperation:request]; //queue is an NSOperationQueue
I have triple checked all of the login details/url, everything is correct, i would really appreciate any help with this one as i am completely lost.
--
Update:
Lighthouse have acknowledged a bug regarding headers on their side. Waiting on a solution from them.
Did you check that the headers sent using your browser are also the same as when you send the request by code?
Especially did you try to add the "Accept" header to your request to define that you accept the json Content-Type?
[request addRequestHeader:#"Accept" value:#"application/json"];
Try using a tool like wireshark or charlesproxy to compare the working requests from your browser/postie, and compare them to the non-working requests from ASIHTTPRequest - once you spot what's different it should be easy to fix.
AliSoftware's suggestion is one of the most likely differences you'll see, but it's possible there are other things too.