有一个改造界面:
public interface GetDataService {
@GET("/news")
Call<ItemAPI> getAllItems();
}
执行请求时如何提供参数?例如,
/news?id=1001
我认为它一定是这样的:
@GET("/news?id={id}")
但是我该怎么做呢?
答案 0 :(得分:2)
@GET("/v1/news_content")
Call<ItemPageAPI> getAllItems(@Query("id") String id);
@Query可以将参数本身添加到URL。
答案 1 :(得分:0)
请像这样使用它:
Using TensorFlow backend. Traceback (most recent call last): File
"D:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import * File "D:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py",
line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper() File "D:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py",
line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) File "D:\Anaconda3\lib\imp.py", line 242, in
load_module
return load_dynamic(name, filename, file) File "D:\Anaconda3\lib\imp.py", line 342, in load_dynamic
return _load(spec) ImportError: DLL load failed: 找不到指定的模块。
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "E:/PythonProject/Test.py",
line 10, in <module>
from keras.layers import Dropout,Dense File "D:\Anaconda3\lib\site-packages\keras\__init__.py", line 3, in
<module>
from . import utils File "D:\Anaconda3\lib\site-packages\keras\utils\__init__.py", line 6, in
<module>
from . import conv_utils File "D:\Anaconda3\lib\site-packages\keras\utils\conv_utils.py", line 9, in
<module>
from .. import backend as K File "D:\Anaconda3\lib\site-packages\keras\backend\__init__.py", line 89,
in <module>
from .tensorflow_backend import * File "D:\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py",
line 5, in <module>
import tensorflow as tf File "D:\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 24, in
<module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import File
"D:\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line
49, in <module>
from tensorflow.python import pywrap_tensorflow File "D:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 74, in <module>
raise ImportError(msg) ImportError: Traceback (most recent call last): File
"D:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import * File "D:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py",
line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper() File "D:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py",
line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) File "D:\Anaconda3\lib\imp.py", line 242, in
load_module
return load_dynamic(name, filename, file) File "D:\Anaconda3\lib\imp.py", line 342, in load_dynamic
return _load(spec) ImportError: DLL load failed: 找不到指定的模块。
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
Process finished with exit code 1
如果@GET("/news?id={id}")
Call<ItemAPI> getAllItems(@Path("id") String idStr);
注释不起作用,则可以传递@Path
注释。
答案 2 :(得分:0)
public interface GetDataService {
@GET("/news?id={id}")
Call<ItemAPI> getAllItems(@Query("id") int id);
}
答案 3 :(得分:0)
您可以通过这种方式在改装请求中设置参数,标题
@Headers("Accept: " + "application/json")
@GET(Constants.GET_PROPERTIES)
fun getFilteredProperties(@Query("access_token") access_token: String,
@Query("lat") lat: String,
@Query("long") long: String,
@Query("current_page") current_page: String,
@Query("location_name") location_name: String
): Call<GetPropertiesPojo>