小编neu*_*t47的帖子

改造:无法为类创建@Body转换器

我需要通过改造2发送下一个json:

{
    "Inspection": {
        "UUID": "name",
        "ModifiedTime": "2016-03-09T01:13",
        "CreatedTime": "2016-03-09T01:13",
        "ReviewedWith": "name2",
        "Type": 1,
        "Project": {
            "Id": 41
        },
        "ActionTypes": [1]
    }   
}
Run Code Online (Sandbox Code Playgroud)

带标题: Authorization: access_token_value

我试过这个:

//header parameter
String accessToken = Requests.getAccessToken();

JsonObject obj = new JsonObject();
JsonObject inspection = new JsonObject();

inspection.addProperty("UUID","name");
inspection.addProperty("ModifiedTime","2016-03-09T01:13");
inspection.addProperty("CreatedTime","2016-03-09T01:13");
inspection.addProperty("ReviewedWith","name2");
inspection.addProperty("Type","1");

JsonObject project = new JsonObject();
project.addProperty("Id", 41);

inspection.add("Project", project);
obj.add("Inspection", inspection);

Retrofit restAdapter = new Retrofit.Builder()
        .baseUrl(Constants.ROOT_API_URL)
        .addConverterFactory(GsonConverterFactory.create())
        .addConverterFactory(ScalarsConverterFactory.create())
        .build();
IConstructSecureAPI service = restAdapter.create(IConstructSecureAPI.class);
Call<JsonElement> result = service.addInspection(accessToken, obj);
JsonElement element = …
Run Code Online (Sandbox Code Playgroud)

java json retrofit retrofit2

11
推荐指数
3
解决办法
1万
查看次数

改造:如何等待回应

我有AsyncTask和doInBackground方法,我在其中使用Retrofit发送POST请求.我的代码看起来像:

    //method of AsyncTask
    protected Boolean doInBackground(Void... params) {
        Retrofit restAdapter = new Retrofit.Builder()
                .baseUrl(Constants.ROOT_API_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        IConstructSecureAPI service = restAdapter.create(IConstructSecureAPI.class);
        //request
        Call<JsonElement> result = service.getToken("TestUser", "pass", "password");
        result.enqueue(new Callback<JsonElement>() {
            @Override
            public void onResponse(Call<JsonElement> call, Response<JsonElement> response) {

            }

            @Override
            public void onFailure(Call<JsonElement> call, Throwable t) {

            }
        });

        return true;
    }
Run Code Online (Sandbox Code Playgroud)

我的问题是:异步发送请求并在执行时,doInBackground方法返回值.所以我需要在同一个线程中发送一个请求,即序列中的所有执行.逐一.并且在请求完成后从doInBackground返回.如何使用Retrofit在同一个线程中发送请求?

java android retrofit

9
推荐指数
1
解决办法
1万
查看次数

改造:500内部服务器错误

每当我尝试通过Retrofit发送POST请求时,我有500个内部服务器错误.当我发送GET请求时,它正确发送.我确信在服务器端,每一件事都可以.我的代码出了什么问题?

    String ENDPOINT = "http://52.88.40.210";
    //model for request
        FriendModel ff = new FriendModel();
        ff.setFriendNumber("380935275259");
        ff.setId(516);
        ff.setNumber("380936831127");

        RestAdapter adapter = new RestAdapter.Builder()
                .setEndpoint(ENDPOINT)
                .build();
        WayfAPI api = adapter.create(WayfAPI.class);
        api.getFriendsLocation(ff, new Callback<List<FriendLocationModel>>() {
            @Override
            public void success(List<FriendLocationModel> friendLocationModels, Response response) {
                for (FriendLocationModel ff : friendLocationModels) {
                    Log.d("myLogs", "===========Successful==========");
                    Log.d("myLogs", "Id: " + ff.getId());
                    Log.d("myLogs", "Number: " + ff.getNumber());
                    Log.d("myLogs", "GeoLocation: : " + ff.getGeoLocation());
                }
            }

            @Override
            public void failure(RetrofitError error) {
                Log.d("myLogs", "-------ERROR-------");
                Log.d("myLogs", Log.getStackTraceString(error));
            }
        });
    }
Run Code Online (Sandbox Code Playgroud)

请求声明:

@Headers({ …
Run Code Online (Sandbox Code Playgroud)

java rest android retrofit

7
推荐指数
1
解决办法
2万
查看次数

Amazon S3:如何获取存储桶中的文件夹列表?

所有我发现的,这是这个方法GET Bucket 但是我无法理解如何才能获得当前文件夹中的文件夹列表.我需要使用哪个前缀和分隔符?这有可能吗?

c# amazon-s3 amazon-web-services aws-sdk

7
推荐指数
4
解决办法
2万
查看次数

Cloud Functions:如何上传额外的文件以在代码中使用?

我需要访问protoc我的代码中的文件。在本地我只是把它放在文件夹中,但是如何从部署的 Firebase 函数中获取这个文件?

const grpc = require('grpc');
const PROTO_PATH = __dirname + '\\protos\\prediction_service.proto';

exports.helloWorld = functions.https.onRequest((request, response){
    var tensorflow_serving = grpc.load(PROTO_PATH).tensorflow.serving;
...
}
Run Code Online (Sandbox Code Playgroud)

node.js firebase google-cloud-platform google-cloud-functions

7
推荐指数
3
解决办法
9791
查看次数

与发布配置文件名称相关的ASP.NET web.config转换

我的ASP.NET MVC项目有三个发布配置文件.

在此输入图像描述

我需要为所有这些添加转换.为此,我在web.config文件中选择了"添加配置转换"并获得了4个Web配置:

在此输入图像描述

但是我无法理解如何将它们中的任何一个分配给任何发布配置文件.例如,我找不到用于开发发布配置文件的put转换的正确配置文件.我怎样才能做到这一点 ?谢谢你的建议.

c# asp.net asp.net-mvc

6
推荐指数
1
解决办法
3188
查看次数

如何从片段中获取 EditText

我创建了 AlerDialog:

AlertDialog.Builder alert = new AlertDialog.Builder(appContext);

                alert.setTitle("Add subcontractors").setView(R.layout.add_subcontractor_form);
                
                //final EditText input = new EditText(appContext);

                alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        String YouEditTextValue = input.getText().toString();
                    }
                });

                alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // what ever you want to do with No option.
                    }
                });

                alert.show();
Run Code Online (Sandbox Code Playgroud)

并为其布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
           <EditText
            android:layout_margin="10dp"
            android:id="@+id/et_sub_name"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:hint="Type name here"
            android:textSize="20sp"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我的问题是,如何在代码中从我的布局中获取 EditText 视图?因为我想在用户按下“确定”按钮后输入文本。

android android-fragments

4
推荐指数
1
解决办法
2093
查看次数

AWS S3 - ListObjects 返回不完整的目录列表

我使用ListObject没有任何分隔符的函数,结果我有一些看起来像:

/BF
/BF/FTP
/BF/MUSIC/LIBRARY/AUDITION/BEAKING%20EARLY.MP3
/BF/VIDEO/
/BF/VIDEO/Example
/BF/VIDEO/Example/test.mp4
Run Code Online (Sandbox Code Playgroud)

问题出在音乐文件夹中。为什么 ListObjects 不返回带有键的 S3Object:“/BF/MUSIC”。有许多 S3Objects 有同样的问题。为什么会这样?

c# amazon-s3 amazon-web-services aws-sdk

3
推荐指数
1
解决办法
1252
查看次数

Firebase:如何调试 onCall 函数?

我正在使用Google Cloud Functions Emulator在本地调试我的 Firebase 函数。Firebase 建议使用functions.https.onCall 函数而不是 functions.https.onRequest避免直接使用 http 调用。相反,Firebase 建议使用Firebase Functions SDK从代码调用此类函数。因为functions.https.onRequest我使用了http-trigger标志,但如何调试onCall功能?

firebase google-cloud-functions

3
推荐指数
1
解决办法
2172
查看次数

使用Retrofit 2上传文件

我试着这几天,我真的做了一切..这是请求在Postman中的样子: 在此输入图像描述

在此输入图像描述

我确信,所有GET参数都写得正确.我想,我如何发送文件上传的问题.

            Map<String, RequestBody> map = new HashMap<>();
            File file = new File("/storage/emulated/0/ConstructSecure/d1940b05-76d1-4d98-b4b4-b04b8247c8cb.png");
            RequestBody requestBody = RequestBody.create(MediaType.parse("image/png"), file);
            String fileName = file.getName();
            map.put("attachment\"; filename=\"" + fileName + "\"", requestBody);

            //GET parameters
            Map<String, String> params = new HashMap<String, String>();
            params.put("inspectionUUID", inspectionUUID);
            params.put("noteUUID", noteUUID);
            params.put("attachmentUUID", attachmentUUID);
            params.put("noteType", noteType);
            params.put("modifiedTime", modifiedTime);

            Call<ResponseBody> call = service.upload(access_token,params,map);
            call.enqueue()....
Run Code Online (Sandbox Code Playgroud)

接口:

@Multipart
    @POST("api/MediaFiles/AddMediaFile")
    Call<ResponseBody> upload(
            @Header("Authorization") String authorization,
            /* GET params */ @QueryMap Map<String, String> params,
            @PartMap Map<String, RequestBody> map
    );
Run Code Online (Sandbox Code Playgroud)

谁能帮助我?

android file-upload retrofit retrofit2

2
推荐指数
1
解决办法
2060
查看次数