How can I use the get method with the request parameter and header in a flutter, I have used the https://pub.dev/packages/http for calling Get API.
response=await _client.get(Uri.http(url, payload),headers: header);
Error:- [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled
Exception: FormatException: Invalid radix-10 number (at character 1)
E/flutter ( 2603): //demo.test/text/public/user/user_list
E/flutter ( 2603): ^
The problem here may be payload that you are trying to send, get method in the http library does not support such a thing. So use post method instead if you need to send data to the server. I had the same issue some time ago and I found that creators of this library are very strict on purposes of each of the methods.
Related
This question already has answers here:
The argument type 'String' can't be assigned to the parameter type 'Uri'
(2 answers)
Closed 1 year ago.
I was trying to get information from an API endpoint by using:
Response response= await get('https://jsonplaceholder.typicode.com/todos/1');
but this didnt work so I had to parse it using Uri:
Response response= await get(Uri.parse('https://jsonplaceholder.typicode.com/todos/1'));
Why do we need to use Uri to parse the HTTP address?
Uri.parse method validates the provided URL.
If the provided URL is not valid, you see exception in console
Flutter team says:
If start and end are provided, they must specify a valid substring of
uri, and only the substring from start to end is parsed as a URI. If
the uri string is not valid as a URI or URI reference, a
FormatException is thrown.
You can learn more from here
Surely, Uri.parse method is most powerful than sending request to server before validation the URL
I want to send in this form in http.post
but I can't manage to encode my data in my body.
I have an error:
[ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception:
Converting object to **
> an encodable object failed: Instance of 'MappedListIterable<User, Set>'
> E/flutter ( 7489): #0 _JsonStringifier.writeObject (dart:convert/json.dart:688:7)
The data could not have been inputted by a typical user due to client-side validation. Is "400 Bad Request" the appropriate status code?
If you are certain the form is invalid 400 Bad Request is acceptable. However depending on why you believe a form is invalid you may also choose to use
status code 422 Unprocessable Entity.
This status code is designed to handle the use case where an submitted request is understood by the server and the request is syntactically correct, but the server was unable to process the instructions contained within the request.
Another possibly appropriate error code would be 415 Unsupported Media Type. This error code should be used when the server fails to understand the request due to an invalid type of form. For example, if a server expected a JSON value but was given XML it should in theory return a 415 Unsupported Media Type code.
I've built an interface to a thridparty Rest/Json web API, everything is working great with valid test cases, but when I request something invalid from the API, say a job that doesn't exist, the API returns a response where the body = 'null' and has a the content type as "application/json; charset=utf-8". I'm not sure if this is standard practice for a web API, but when I call Execute on the IHttpClient I end up with an Access Violation and the client exits.
Protrace is a follows
Exception code: C0000005 ACCESS_VIOLATION
Fault address: 00007FFC6733DAAD 01:000000000077CAAD C:\Apps\Progress\117\bin\prow.dll
** ABL Stack Trace **
--> Write OpenEdge.Net.HTTP.Filter.Payload.JsonEntityWriter at line 463 (OpenEdge/Net/HTTP/Filter/Payload/JsonEntityWriter.r)
ExtractEntity OpenEdge.Net.HTTP.Lib.ABLSockets.ABLSocketLibrary at line 360 (OpenEdge/Net/HTTP/Lib/ABLSockets/ABLSocketLibrary.r)
Execute OpenEdge.Net.HTTP.Lib.ABLSockets.ABLSocketLibrary at line 312 (OpenEdge/Net/HTTP/Lib/ABLSockets/ABLSocketLibrary.r)
Execute OpenEdge.Net.HTTP.HttpClient at line 154 (OpenEdge/Net/HTTP/HttpClient.r)
TryRest Tempo.TempoApi at line 1264 (D:\_Dev\OnTap-Trunk\rcode\Tempo\TempoApi.r)
ExecuteRest Tempo.TempoApi at line 234 (D:\_Dev\OnTap-Trunk\rcode\Tempo\TempoApi.r)
TryRest is:
METHOD PRIVATE INTEGER TryRest(
INPUT oUri AS URI,
INPUT cType AS CHARACTER,
INPUT cContentType AS CHARACTER,
INPUT oContent AS Object,
OUTPUT oResponse AS IHttpResponse ):
DEFINE VARIABLE result AS INTEGER NO-UNDO.
DEFINE VARIABLE oRequest AS IHttpRequest NO-UNDO.
CASE cType:
WHEN "GET" THEN
oRequest = RequestBuilder:GET(oURI)
:AddHeader("Authorization", "Bearer " + STRING(cAccessToken))
:AcceptJson()
:REQUEST.
END CASE.
oResponse = ResponseBuilder:Build():Response.
oClient:EXECUTE(oRequest,oResponse).
RETURN oResponse:StatusCode.
CATCH e AS Progress.Lang.Error:
UNDO, THROW e.
END CATCH.
END METHOD.
I'm using the latest OpenEdge client, 11.7.2 Windows x64.
My question is, is it normal for a web API to return 'Null' for an invalid request?
And secondly, this is obviously an unhandled exception in OpenEdge.Net.HTTP.Lib, which should not result in client crash.. Any ideas for working around it? I've tried changing AcceptJson() to AcceptAll, and AcceptHTML, but the protrace is the same, crashing in JsonEntityWriter.
Thanks
No, typically RESTful APIs will return a 404 if you make a request to a route that isn't valid. The only exception that I can think of off the top of my head is if you attempt to access a route that has parameters as part of the URI.
sometimes i got error when i include your class(AuthnetCim.class) in my controller.
the error is as below:-
Fatal error: Uncaught exception
‘Zend_Controller_Response_Exception’
with message ‘Cannot send headers;
headers already sent in
/home/newwebsi/public_html/B4BPHP/public/include/AuthnetCIM.class.php,
line 1′ in
/home/newwebsi/public_html/B4BPHP/library/Zend/Controller/Response/Abstract.php:321
Stack trace: #0
/home/newwebsi/public_html/B4BPHP/library/Zend/Controller/Response/Abstract.php(148):
Zend_Controller_Response_Abstract->canSendHeaders(true)
#1 /home/newwebsi/public_html/B4BPHP/library/Zend/Controller/Action/Helper/Redirector.php(226):
Zend_Controller_Response_Abstract->setRedirect(‘/B4BPHP/public/…’,
302) #2
/home/newwebsi/public_html/B4BPHP/library/Zend/Controller/Action/Helper/Redirector.php(370):
Zend_Controller_Action_Helper_Redirector->_redirect(‘/B4BPHP/public/…’)
#3 /home/newwebsi/public_html/B4BPHP/library/Zend/Controller/Action/Helper/Redirector.php(453):
Zend_Controller_Action_Helper_Redirector->setGotoUrl(‘index/login’, Array) #4
/home/newwebsi/public_html/B4BPHP/library/Zend/Controller/Action.php(68
in
/home/newwebsi/public_html/B4BPHP/library/Zend/Controller/Response/Abstract.php
on line 321
when i remove this class i do not get any error anywhere
Please, help me to resolve this error
Make sure you do not have any characters before <?php in AuthnetCIM.class.php.
Ouput is sent to the browser when the file AuthnetCIM.class.php is looked-up/included.
Check for spaces, BOM before the opening PHP tag, echoing/printing statements.
In other words check for anything that might be causing the script to output data.