@@ -251,16 +251,22 @@ def set_server_url(self, url=None ,timeout=5):
251251 return result
252252 return {"response" : "Missing arguments : url" , "status" : Status .ERROR }
253253
254- def get (self , header_mode = 0 , timeout = 60 ):
254+ def get (self , data = "" , header_mode = 0 , input_timeout = 5 , timeout = 60 ):
255255 """
256256 Function for sending HTTP GET request
257257
258258 Parameters
259259 ----------
260+ data : str
261+ The full header for the GET request if header_mode is set.
260262 header_mode : int
261263 Customization of HTTP(S) request header)(default=0)
262264 0 --> Disable
263265 1 --> Enable
266+ input_timeout : int
267+ Input timeout (default=5)
268+ timeout : int
269+ Timeout (default=60)
264270
265271 Returns
266272 -------
@@ -276,11 +282,23 @@ def get(self, header_mode=0, timeout=60):
276282 status : int
277283 Status of the command.
278284 """
279- if header_mode == 1 :
280- return {"response" : "Not implemented yet!" , "status" : Status .ERROR }
281-
282- command = f'AT+QHTTPGET={ timeout } '
283- return self .atcom .send_at_comm (command ,"OK" )
285+ # Set the request header config.
286+ result = self .set_request_header_status (status = header_mode )
287+ if result ["status" ] == Status .SUCCESS :
288+ if header_mode == 1 :
289+ # Send a GET request to the modem.
290+ command = f'AT+QHTTPGET={ timeout } ,{ len (data )} ,{ input_timeout } '
291+ result = self .atcom .send_at_comm (command , "CONNECT" , timeout = 60 )
292+ if result ["status" ] == Status .SUCCESS :
293+ # Send the request header.
294+ return self .atcom .send_at_comm (data , "OK" , line_end = False )
295+ else :
296+ # Send a GET request without header.
297+ command = f'AT+QHTTPGET={ timeout } '
298+ return self .atcom .send_at_comm (command ,"OK" )
299+
300+ # Return the result of request header if there is no SUCCESS.
301+ return result
284302
285303 def post (self , data , header_mode = 0 , input_timeout = 5 , timeout = 60 ):
286304 """
@@ -314,14 +332,15 @@ def post(self, data, header_mode=0, input_timeout=5, timeout=60):
314332 status : int
315333 Status of the command.
316334 """
317- if header_mode == 1 :
318- return {"response" : "Not implemented yet!" , "status" : Status .ERROR }
319-
320- command = f'AT+QHTTPPOST={ len (data )} ,{ input_timeout } ,{ timeout } '
321- result = self .atcom .send_at_comm (command ,"CONNECT" , timeout = timeout )
322-
335+ # Set the request header config.
336+ result = self .set_request_header_status (status = header_mode )
323337 if result ["status" ] == Status .SUCCESS :
324- result = self .atcom .send_at_comm (data , "OK" , line_end = False ) # send data
338+ # Send a POST request to the modem.
339+ command = f'AT+QHTTPPOST={ len (data )} ,{ input_timeout } ,{ timeout } '
340+ result = self .atcom .send_at_comm (command ,"CONNECT" , timeout = timeout )
341+ if result ["status" ] == Status .SUCCESS :
342+ # Send the request (header and) body.
343+ result = self .atcom .send_at_comm (data , "OK" , line_end = False )
325344 return result
326345
327346 def post_from_file (self , file_path , header_mode = 0 , timeout = 60 ):
@@ -390,14 +409,15 @@ def put(self, data, header_mode=0, input_timeout=5, timeout=60):
390409 status : int
391410 Status of the command.
392411 """
393- if header_mode == 1 :
394- return {"response" : "Not implemented yet!" , "status" : Status .ERROR }
395-
396- command = f'AT+QHTTPPUT={ len (data )} ,{ input_timeout } ,{ timeout } '
397- result = self .atcom .send_at_comm (command ,"CONNECT" )
398-
412+ # Set the request header config.
413+ result = self .set_request_header_status (status = header_mode )
399414 if result ["status" ] == Status .SUCCESS :
400- result = self .atcom .send_at_comm (data , "OK" , line_end = False ) # send data
415+ # Send a PUT request to the modem.
416+ command = f'AT+QHTTPPUT={ len (data )} ,{ input_timeout } ,{ timeout } '
417+ result = self .atcom .send_at_comm (command ,"CONNECT" )
418+ if result ["status" ] == Status .SUCCESS :
419+ # Send the request (header and) body.
420+ result = self .atcom .send_at_comm (data , "OK" , line_end = False )
401421 return result
402422
403423 def put_from_file (self , file_path , file_type = 0 , header_mode = 0 , timeout = 60 ):
0 commit comments