0
I would like help processing an HTTP request in Flutter (in this case using the SEARCH method to filter files on a Webdav (Nextcloud) file server where I need to send XML type data in the request body.
[x] I can execute the command via Curl using the --data parameter:
curl -u user:senha -X SEARCH 'https://host123.com.br/remote.php/dav' -H "content-Type: text/xml" --data '<?xml version="1.0" encoding="UTF-8"?><d:searchrequest xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns"><d:basicsearch><d:select><d:prop><d:displayname/></d:prop></d:select><d:from><d:scope><d:href>/files/wprech</d:href><d:depth>infinity</d:depth></d:scope></d:from><d:where><d:and><d:or><d:eq><d:prop><d:getcontenttype/></d:prop><d:literal>image/png</d:literal></d:eq><d:eq><d:prop><d:getcontenttype/></d:prop><d:literal>image/jpg</d:literal></d:eq><d:eq><d:prop><d:getcontenttype/></d:prop><d:literal>video/mp4</d:literal></d:eq></d:or></d:and></d:where><d:orderby/></d:basicsearch></d:searchrequest>'
[x] I can also process via Postman:
[ ] I’m not able to process this request that needs to send a body inside Flutter/Dart. For all other HTTP requests of the project we use pkg DIO, which is working well, in which it is not necessary to send a body. The nearest code is this below:
void _list() async {
final prefs = await SharedPreferences.getInstance();
var us = prefs.getString('id') ?? '';
var sn = prefs.getString('password') ?? '';
String basicAuth = 'Basic ' + base64Encode(utf8.encode('$us:$sn'));
try {
Dio dio = new Dio();
dio.options.method = 'SEARCH';
dio.options.responseType = ResponseType.plain;
dio.options.headers = {
HttpHeaders.authorizationHeader: basicAuth,
'content-Type': 'text/xml'
};
String data =
'<?xml version="1.0" encoding="UTF-8"?><d:searchrequest xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns"><d:basicsearch><d:select><d:prop><d:displayname/></d:prop></d:select><d:from><d:scope><d:href>/files/wprech</d:href><d:depth>infinity</d:depth></d:scope></d:from><d:where><d:and><d:or><d:eq><d:prop><d:getcontenttype/></d:prop><d:literal>image/png</d:literal></d:eq><d:eq><d:prop><d:getcontenttype/></d:prop><d:literal>image/jpg</d:literal></d:eq><d:eq><d:prop><d:getcontenttype/></d:prop><d:literal>video/mp4</d:literal></d:eq></d:or></d:and></d:where><d:orderby/></d:basicsearch></d:searchrequest>';
Response response = await dio.request(
"https://host123.com.br/remote.php/dav",
data: data);
print(response);
} catch (e) {
print(e);
}}
Server responses range from 400, 404, 500 and 501, depending on how it is sent:
I/flutter ( 6767): DioError [DioErrorType.RESPONSE]: Http status error [400]
Any help is welcome. :)
Thanks @Matheus I managed to solve.
– Gabrielhn
Oops ball show then, abrass
– Matheus