@@ -35,10 +35,10 @@ module http_client
3535
3636contains
3737 ! Constructor for request_type type.
38- function new_request (url , method , header , json ) result(response)
38+ function new_request (url , method , header , data ) result(response)
3939 integer , intent (in ), optional :: method
4040 character (len=* ), intent (in ) :: url
41- character (len=* ), intent (in ), optional :: json
41+ character (len=* ), intent (in ), optional :: data
4242 type (header_type), intent (in ), optional :: header(:)
4343 type (request_type) :: request
4444 type (response_type) :: response
@@ -62,9 +62,9 @@ function new_request(url, method, header, json) result(response)
6262 request% header = [header_type(' user-agent' , ' fortran-http/0.1.0' )]
6363 end if
6464
65- if ( present (json)) then
66- request % json = json
67- request% header = [request % header, header_type( ' Content-Type ' , ' application/json ' )]
65+ ! setting the request data to be send
66+ if ( present ( data )) then
67+ request% data = data
6868 end if
6969
7070 ! Populates the response
@@ -111,7 +111,7 @@ & function failed. This can occur due to insufficient memory available in the sy
111111 rc = set_method(curl_ptr, this% request% method, response)
112112
113113 ! setting request body
114- rc = set_body(curl_ptr, this% request% json )
114+ rc = set_body(curl_ptr, this% request% data )
115115
116116 ! setting request header
117117 rc = curl_easy_setopt(curl_ptr, CURLOPT_HTTPHEADER, header_list_ptr);
@@ -187,15 +187,12 @@ function set_method(curl_ptr, method, response) result(status)
187187 end select
188188 end function set_method
189189
190- function set_body (curl_ptr , json ) result(status)
190+ function set_body (curl_ptr , data ) result(status)
191191 type (c_ptr), intent (out ) :: curl_ptr
192- character (* ), intent (in ) :: json
193- integer :: status, json_length
194- json_length = len (json)
195- ! if(json_length > 0) then
196- status = curl_easy_setopt(curl_ptr, CURLOPT_POSTFIELDS, json)
197- status = curl_easy_setopt(curl_ptr, CURLOPT_POSTFIELDSIZE_LARGE, json_length)
198- ! end if
192+ character (* ), intent (in ) :: data
193+ integer :: status
194+ status = curl_easy_setopt(curl_ptr, CURLOPT_POSTFIELDS, data )
195+ status = curl_easy_setopt(curl_ptr, CURLOPT_POSTFIELDSIZE_LARGE, len (data ))
199196 end function set_body
200197
201198 function client_response_callback (ptr , size , nmemb , client_data ) bind(c)
0 commit comments