How to get JSON responce to HTTP Request
Date : March 29 2020, 07:55 AM
wish help you to fix your issue if you are not hitting the wrong endpoint you probably need to set the http accept header to "application/json" like @rckoenes said. What you can also do is try to hit the service using CURL or even your web browser to see if the json service is running. Here is the code it is working for me for requesting a local JSON service created by SOAPUI: NSURLRequest *request = [[NSURLRequest alloc]
initWithURL: [NSURL URLWithString:SERVERURL]
cachePolicy: NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval: 10];
NSURLConnection *connection = [[NSURLConnection alloc]
initWithRequest:request
delegate:self
startImmediately:YES];
if(!connection) {
DLog(@"connection failed");
} else {
DLog(@"Connection succeeded");
}
|
DRYing in JSON responce or request
Date : March 29 2020, 07:55 AM
|
Problems in implementing responce for RTSP's SETUP request
Tag : java , By : PsyberMonkey
Date : March 29 2020, 07:55 AM
may help you . As always, posting stupid questions to stackoverflow helps to find out the problem by myself (looks like a kind of Murphy law; I have to post it 3 hours ago to save my sleeping!) The key word was (plus 2 additional bytes)
(plus 2 additional bytes)
[0x7f73900013f8] live555 demux debug: RTP subsession 'video/JPEG'
|
tcpdump http request/responce Wireshark
Tag : linux , By : simonth
Date : March 29 2020, 07:55 AM
hop of those help? dst port 8080 - this captures traffic with destination port 8080 only. The response packets have soruce port 8080, but the destination port will be some random port selected by the client. Change the filter to port 8080 and you will see packets coming from/to port 8080 (i.e. both directions)
|
Write json responce for each request into a file
Date : March 29 2020, 07:55 AM
wish of those help I wrote a code which is making a request to API and recieving output in JSON. So my question is how to write output for each request in file. Now my code is doing the last one request. , You need to open and keep open the output file before your loop: import requests
import json
with open("query4.txt", "rt") as file:
data_file = file.read()
with open("result.txt", "w") as f_o:
for line in data_file.split("\n"):
drX, drY, fromX, fromY, dist = line.split(",")
url = "https://api.openrouteservice.org/directions?"
params = [
["api_key", "my_api_key"],
["coordinates", "%s,%s|%s,%s" % (drY, drX, fromY, fromX)],
["profile", "driving-car"]
]
headers = {
"Accept": "application/json, application/geo+json,"
"application/gpx+xml, img/png; charset=utf-8"}
responce = requests.get(url=url, params=params, headers=headers)
# print(responce.url)
# print(responce.text)
result = json.loads(responce.text)
# print(result)
for rows in result["routes"]:
print(rows["summary"]["distance"], file=f_o) # depending on how do you want the result
# print(result["routes"])
|