Api结束空结果 - C#

时间:2017-11-22 14:56:57

标签: c# api

我正在使用C#创建一个带有Api的应用,但是在我的应用中,我收到了无效请求,而使用相同的api url,它会在邮递员中给出正确的结果。有人知道为什么会这样吗?

        // Internal storage where the DexClassLoader writes the optimized dex file to.
        final File optimizedDexOutputPath = getDir(SECONDARY_DEX_INTERNAL_DIR, Context.MODE_PRIVATE);

        // Initialize the class loader with the secondary dex file.
        DexClassLoader cl = new DexClassLoader(dexInternalStoragePath.getAbsolutePath(),
                                                optimizedDexOutputPath.getAbsolutePath(),
                                                null,
                                                getClassLoader());
        Class libProviderClazz = null;//variable libProviderClazz of type Class

        try {
            // Load the library class from the class loader.
            libProviderClazz = cl.loadClass(PROVIDER_CLASS);

            // Cast the return object to the library interface so that the
            // caller can directly invoke methods in the interface.

            // Alternatively, the caller can invoke methods through reflection,
            // which is more verbose and slow.
            LibraryInterface lib = (LibraryInterface) libProviderClazz.newInstance();

        }
        catch (Exception exception)
        {
            // Handle exception gracefully here.
            exception.printStackTrace();
        }

使用带有以下代码的api url:

http://api.tradeskillmaster.com/v1/item/EU/ragnaros/82800?format=json&apiKey=****

有人知道我运行我的应用程序时为什么会失效吗?我错过了一些代码吗?

2 个答案:

答案 0 :(得分:2)

请求网址不正确。通过将BaseAddress设置为http://api.tradeskillmaster.com/v1/item/EU/ragnaros/82800?format=json&apiKey=...并将GetAsync设置为api/emp,您最终会收到http://api.tradeskillmaster.com/v1/item/EU/ragnaros/api/emp的请求。你可以用调试器看到这个:

screenshot of debugging info

BaseAddress应该是不会改变的部分,GetAsync的参数应该是更改的部分,相对BaseAddress

答案 1 :(得分:0)

这可能对你有所帮助......

            using (var client = new HttpClient())
            {
                var response = client.GetAsync("http://api.tradeskillmaster.com/v1/item/EU/ragnaros/82800?format=json&apiKey=test").Result;

                if (response.IsSuccessStatusCode)
                {
                    var result = response.Content.ReadAsStringAsync();
                    var resultObject = JsonConvert.DeserializeObject<yourobject>(result.Result);
                    return resultObject;
                }
            }