身份验证失败使用Android Volley请求Wowza REST API

时间:2016-05-11 21:25:25

标签: android video-streaming android-volley restful-authentication wowza

我正在尝试在我的应用程序中获取我的Wowza媒体服务器上的传入流列表,以便为每个流可用动态生成一个播放按钮。我找到了我需要的请求here

由于已经存在不同的身份验证失败错误主题,我遇到了不同的解决方案,并且我找到了这段代码,但仍然无效:

我的CustomRequest类:

    import android.util.Base64;
    import java.io.UnsupportedEncodingException;
    import java.util.HashMap;
    import java.util.Map;
    import org.json.JSONException;
    import org.json.JSONObject;

    import com.android.volley.AuthFailureError;
    import com.android.volley.NetworkResponse;
    import com.android.volley.ParseError;
    import com.android.volley.Request;
    import com.android.volley.Response;
    import com.android.volley.Response.ErrorListener;
    import com.android.volley.Response.Listener;
    import com.android.volley.toolbox.HttpHeaderParser;

public class CustomRequest extends Request<JSONObject> {

private Listener<JSONObject> listener;
private Map<String, String> params;



public CustomRequest(int method, String url, Map<String, String> params,
                     Listener<JSONObject> reponseListener, ErrorListener errorListener) {
    super(method, url, errorListener);
    this.listener = reponseListener;
    this.params = params;
}
/*@Override
protected Map<String, String> getParams()
        throws com.android.volley.AuthFailureError {
    return params;
};*/

@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
    try {
        String jsonString = new String(response.data,
                HttpHeaderParser.parseCharset(response.headers));
        return Response.success(new JSONObject(jsonString),
                HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));
    } catch (JSONException je) {
        return Response.error(new ParseError(je));
    }
}

@Override
protected void deliverResponse(JSONObject response) {
    // TODO Auto-generated method stub
    listener.onResponse(response);
}

@Override
public Map<String, String> getParams() /* or getHeaders() ?*/ throws AuthFailureError {
    HashMap<String, String> params = new HashMap<String, String>();
    String creds = String.format("%s:%s",AppConfig.PUBLISHER_USERNAME,AppConfig.PUBLISHER_PASSWORD);
    String auth = "Basic " + Base64.encodeToString(creds.getBytes(), Base64.NO_WRAP);
    params.put("Authorization", auth);
    return params;
}
} ` 

它的实例:

// Instantiate the RequestQueue.
    RequestQueue queue = Volley.newRequestQueue(this);
    String url ="http://192.168.1.150:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/live/instances";
    Map<String, String> params=new HashMap<>();
    params.put("username",AppConfig.PUBLISHER_USERNAME);
    params.put("password",AppConfig.PUBLISHER_PASSWORD);

// Request a string response from the provided URL.
    final TextView mTxtDisplay;
    mTxtDisplay = (TextView) findViewById(R.id.txtDisplay);

    CustomRequest jsObjRequest = new CustomRequest(Request.Method.GET, url, params, new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {
                    Log.e("req", "good");
                    mTxtDisplay.setText("Response: " + response.toString());
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    // TODO Auto-generated method stub
                    Log.e("req", error.toString());
                }


    });


// Access the RequestQueue through your singleton class.
    MySingleton.getInstance(this).addToRequestQueue(jsObjRequest);

这是logcat:

05-11 23:35:22.763 2170-2170/? E/NetworkScheduler.SchedulerReceiver: Invalid parameter app
05-11 23:35:22.763 2170-2170/? E/NetworkScheduler.SchedulerReceiver: Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
05-11 23:35:25.359 9003-9059/? E/Volley: [9916] BasicNetwork.performRequest: Unexpected response code 401 for http://192.168.1.150:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/live/instances
05-11 23:35:25.548 9003-9059/? E/Volley: [9916] BasicNetwork.performRequest: Unexpected response code 401 for http://192.168.1.150:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/live/instances
05-11 23:35:25.549 9003-9003/? E/req: com.android.volley.AuthFailureError
05-11 23:35:26.093 3866-3866/? E/ReflectionReceiver: Unrecognized event: android.intent.action.PACKAGE_ADDED
05-11 23:35:26.471 315-459/? E/Vold: Failed to find mounted volume for /storage/sdcard1/Android/data/com.google.android.apps.magazines/cache/
05-11 23:35:26.474 315-459/? E/Vold: Failed to find mounted volume for /storage/sdcard1/Android/data/com.google.android.apps.magazines/files/
05-11 23:35:26.505 315-459/? E/Vold: Failed to find mounted volume for /storage/sdcard1/Android/data/com.google.android.apps.magazines/cache/
05-11 23:35:26.509 315-459/? E/Vold: Failed to find mounted volume for /storage/sdcard1/Android/data/com.google.android.apps.magazines/files/
05-11 23:35:26.888 9211-9211/? E/ApkAssets: Error while loading asset assets/natives_blob_64.bin: java.io.FileNotFoundException: assets/natives_blob_64.bin
05-11 23:35:26.888 9211-9211/? E/ApkAssets: Error while loading asset assets/snapshot_blob_64.bin: java.io.FileNotFoundException: assets/snapshot_blob_64.bin
05-11 23:35:27.224 2170-2170/? E/NetworkScheduler.SchedulerReceiver: Invalid parameter app
05-11 23:35:27.224 2170-2170/? E/NetworkScheduler.SchedulerReceiver: Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
05-11 23:35:37.552 884-1329/? E/WifiStateMachine: WifiStateMachine CMD_START_SCAN source 10017 txSuccessRate=0.00 rxSuccessRate=0.00 targetRoamBSSID=any RSSI=-42
05-11 23:35:37.554 884-1329/? E/WifiStateMachine: [1,463,002,537,554 ms] noteScanStartWorkSource{1000} uid 10017
05-11 23:35:37.718 9342-9383/? E/Babel_SMS: canonicalizeMccMnc: invalid mccmnc 
05-11 23:35:37.721 9342-9383/? E/Babel_SMS: canonicalizeMccMnc: invalid mccmnc nullnull
05-11 23:35:38.210 884-1329/? E/WifiStateMachine: [1,463,002,538,210 ms] noteScanEnd WorkSource{1000}
05-11 23:35:38.214 884-1329/? E/WifiStateMachine: wifi setScanResults statecom.android.server.wifi.WifiStateMachine$ConnectedState@10d3af19 sup_state=COMPLETED debouncing=false
05-11 23:35:39.633 884-1333/? E/ConnectivityService: RemoteException caught trying to send a callback msg for NetworkRequest [ id=131, legacyType=-1, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN] ]
05-11 23:38:16.970 2170-19718/? E/GCM: Raise wifi heartbeat interval to: 1740000 (good hb = 15, bad hb = 0)
05-11 23:40:11.371 2780-19796/? E/XMPPConnectionManager: Failed to connect user '1612759885831405568' to host ' on port 0: XMPPError connecting to :0.: remote-server-error(502) XMPPError connecting to :0.
                                                           -- caused by: java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 0): connect failed: ECONNREFUSED (Connection refused)

我最近开始进行Android开发,所以如果我犯了致命的错误,请原谅。有人看到我的代码出了什么问题吗?

提前感谢您的帮助:)

0 个答案:

没有答案