wordpress_client
wordpress_client copied to clipboard
Request Uri always return host in InternalRequester
Hi, there, in my case, the Rest API url of Wordpress is https://host.com/wp-json/wc/v3, but when we tried to call ListPostRequest , like the example, got error " https://host.com/posts?page=1&per_page=1&order=asc" , the path "/wp-json/wc/v3" was missed.
Hey @liuchiente ! I am not able to reproduce the issue you mentioned. Could you please share more details on this?
- Version you are using
- Steps to reproduce in detail
Thank you!
Hi, sorry for late, following is some information for the exception.
version: wordpress_client: ^8.4.1
main.dart
final baseUrl = Uri.parse('https://example.com/wp-json/wp/v2');
final client = WordpressClient(
baseUrl: baseUrl,
bootstrapper: (bootstrapper) => bootstrapper
.withStatisticDelegate((baseUrl, requestCount) {
print('$baseUrl -> $requestCount');
})
.withDebugMode(true)
.withDefaultAuthorization(
UsefulJwtAuth(
userName: 'username',
password: 'password',
),
)
.build(),
);
client.initialize();
final request = ListPostRequest(
page: 1,
perPage: 20,
order: Order.asc,
);
final wpResponse = await client.posts.list(request);
as bellow, and I had got exception message like this
https://example.com/posts -> 1 *** Request *** uri: https://example.com/posts?page=1&per_page=20&order=asc method: GET responseType: ResponseType.json followRedirects: true persistentConnection: true connectTimeout: 0:00:30.000000 sendTimeout: 0:00:30.000000 receiveTimeout: 0:00:30.000000 receiveDataWhenStatusError: true extra: {} headers: data: null
*** DioException ***: uri: https://example.com/posts?page=1&per_page=20&order=asc DioException [connection error]: The connection errored: The XMLHttpRequest onError callback was called. This typically indicates an error on the network layer. This indicates an error which most likely cannot be solved by the library.
the exception confuse me is, I had set full restful api url https://example.com/wp-json/wp/v2, then ListPostRequest will get all the post from my Wordpress, but the DIO exception means that calling url is https://example.com/posts , the path of url wp/v2 has been missing.
did I made the wrong for calling method ?
@liuchiente I had used the same configuration for my tests and it was working fine. I am now curious on if the website you are using has some plugins which has some redirect rule to redirect the user from API path to the normal webpage. eg: /wp-json/*
If you have Cloudflare, it is also possible you have some redirect there as well for this path. I understand the site URL is sensitive, but if it's possible to DM me the URL, then I could further debug it to know where the issue actually is. As of now, i have retested as well but didn't find any issues on how it's handled in the package.
EDIT: Could you also test by setting followRedirects
as false
? This configuration is available when using the bootstrapper parameter.
Hey @liuchiente , I am closing this one out as there is no activity for past 2 weeks. Please reopen if you have more to add!