排球图库忽略格式= feed&type = rss Params
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了排球图库忽略格式= feed&type = rss Params相关的知识,希望对你有一定的参考价值。
我需要使用Volley库获取rss feed但是Volley一直忽略我的format=feed&type=rss
Params。
我尝试了所有的东西,但我无法让它工作。
这是我的网址:http://almesryoon.com/%D8%AF%D9%81%D8%AA%D8%B1-%D8%A3%D8%AD%D9%88%D8%A7%D9%84-%D8%A7%D9%84%D9%88%D8%B7%D9%86?format=feed&type=rss
注意:此网址适用于Google PostMan
我的SimpleXmlRequest
课程:
public class SimpleXmlRequest<T> extends Request<T> {
private static final Serializer serializer = new Persister();
private final Class<T> clazz;
private final Map<String, String> headers;
private final Listener<T> listener;
/**
* Make HTTP request and return a parsed object from Response
* Invokes the other constructor.
*
* @see SimpleXmlRequest#SimpleXmlRequest(int, String, Class, Map, Listener, ErrorListener)
*/
public SimpleXmlRequest(int method, String url, Class<T> clazz,
Listener<T> listener, ErrorListener errorListener) {
this(method, url, clazz, null, listener, errorListener);
}
/**
* Make HTTP request and return a parsed object from XML Response
*
* @param url URL of the request to make
* @param clazz Relevant class object
* @param headers Map of request headers
* @param listener
* @param errorListener
*
*/
public SimpleXmlRequest(int method, String url, Class<T> clazz, Map<String, String> headers,
Listener<T> listener, ErrorListener errorListener) {
super(method, url, errorListener);
this.clazz = clazz;
this.headers = headers;
this.listener = listener;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
return headers != null ? headers : super.getHeaders();
}
@Override
protected void deliverResponse(T response) {
listener.onResponse(response);
}
@Override
public String getBodyContentType() {
return "application/xml";
}
@Override
protected Response<T> parseNetworkResponse(NetworkResponse response)
{
try {
String data = new String(response.data, HttpHeaderParser.parseCharset(response.headers));// The problem here this data is not XML
return Response.success(serializer.read(clazz, data),
HttpHeaderParser.parseCacheHeaders(response));
}
catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
}
catch (Exception e) {
return Response.error(new VolleyError(e.getMessage()));
}
}
}
此外,我试图使用METHOD.POST
与getParams()
方法
目标rss
:
<?xml version="1.0" encoding="utf-8"?>
<!-- generator="Joomla! - Open Source Content Management" -->
<rss version="2.0"
xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Title</title>
<description>Description</description>
<link>http://google.com</link>
<lastBuildDate>Thu, 31 Mar 2016 01:27:12 +0200</lastBuildDate>
<generator>Joomla! - Open Source Content Management</generator>
<atom:link rel="self" type="application/rss+xml" href="http://example.com/example?format=feed&type=rss"/>
<language>ar-aa</language>
<item>
<title>Item1</title>
<link>http://example.com/example1</link>
<guid isPermaLink="true">http://example.com/example1</guid>
<description>Description1</description>
<author>admin</author>
<category>Category1</category>
<pubDate>Wed, 30 Mar 2016 18:49:37 +0200</pubDate>
</item>
<item>
<title>Item2</title>
<link>http://example.com/example2</link>
<guid isPermaLink="true">http://example.com/example2</guid>
<description>Description2</description>
<author>admin</author>
<category>Category1</category>
<pubDate>Wed, 30 Mar 2016 18:49:37 +0200</pubDate>
</item>
</channel>
</rss>
我正在使用这个代码并且它工作得很好但是HttpParams
,BasicHttpParams
,HttpConnectionParams
,DefaultHttpClient
,HttpGet
,HttpResponse
和HttpEntity
现在已被弃用。
我的工作代码:
StringBuilder chaine = new StringBuilder("");
try {
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.
// The default value is zero, that means the timeout is not used.
int timeoutConnection = AppConstants.CONNECTION_TIMEOUT_SEC * 1000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = AppConstants.SOCKET_TIMEOUT_SEC * 1000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
// request method is GET
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
InputStream inputStream = httpEntity.getContent();
BufferedReader rd = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = rd.readLine()) != null) {
chaine.append(line);
}
rd.close();
} catch (IOException e) {
// writing exception to log
e.printStackTrace();
}
请使用以下网址获取您所需的RSS
https://m.almesryoon.com/%d8%af%d9%81%d8%aa%d8%b1-%d8%a3%d8%ad%d9%88%d8%a7%d9%84-%d8%a7%d9%84%d9%88%d8%b7%d9%86?format=feed&type=rss&template=mobile
这是日志:
...
D/dalvikvm: GC_FOR_ALLOC freed 27K, 12% free 6432K/7303K, paused 20ms, total 20ms
I/onResponse: <?xml version="1.0" encoding="utf-8"?>
<!-- generator="Joomla! - Open Source Content Management" -->
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>دفتر أحوال الوطن - المصريون</title>
<description>المصريون صحيفة يومية مستقلة تنشر آخر وأهم أخبار مصر والوطن العربى والعالم</description>
<link>https://m.almesryoon.com/دفتر-أحوال-الوطن</link>
<lastBuildDate>Thu, 23 Feb 2017 04:36:51 +0200</lastBuildDate>
<generator>Joomla! - Open Source Content Management</generator>
<atom:link rel="self" type="application/rss+xml" href="https://m.almesryoon.com/دفتر-أحوال-الوطن?format=feed&type=rss&template=mobile"/>
<language>ar-aa</language>
<item>
...
在使用您的服务器URL测试一些示例代码后,我发现它得到了301响应。从您的第一个网址,第二个网址将是(https)
https://almesryoon.com/%D8%AF%D9%81%D8%AA%D8%B1-%D8%A3%D8%AD%D9%88%D8%A7%D9%84-%D8%A7%D9%84%D9%88%D8%B7%D9%86?format=feed&type=rss
第三个网址将是:
http://m.almesryoon.com/%d8%af%d9%81%d8%aa%d8%b1-%d8%a3%d8%ad%d9%88%d8%a7%d9%84-%d8%a7%d9%84%d9%88%d8%b7%d9%86?template=mobile
最后的网址是(https):
https://m.almesryoon.com/%d8%af%d9%81%d8%aa%d8%b1-%d8%a3%d8%ad%d9%88%d8%a7%d9%84-%d8%a7%d9%84%d9%88%d8%b7%d9%86?template=mobile
使用此最终URL和下面的示例代码,您将获得200个响应代码。我想你可以用我上面提到的最终网址尝试你的代码。
RequestQueue queue = Volley.newRequestQueue(this);
String url = "https://m.almesryoon.com/%d8%af%d9%81%d8%aa%d8%b1-%d8%a3%d8%ad%d9%88%d8%a7%d9%84-%d8%a7%d9%84%d9%88%d8%b7%d9%86?template=mobile";
StringRequest request = new StringRequest(url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i("onResponse", response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("onErrorResponse", error.toString());
}
});
queue.add(request);
关于在Volley中处理301响应,我还没试过,但是,您可以阅读以下问题以获取更多信息
Android volley to handle redirect
如果你已经尝试过编码你的网址并且它不起作用,那么问题就在于凌空。不幸的是,我遇到了同样的情况,只有使用截击的POST请求。他们在HTTP实现方面完美无缺,但是在凌空时返回400.我当时的解决方案是坚持使用旧的HTTP实现。
以上是关于排球图库忽略格式= feed&type = rss Params的主要内容,如果未能解决你的问题,请参考以下文章
是否有任何其他技术可以用来替代 rss feed 联合技术?
[翻译]Convert a date to the RFC822 standard for use in RSS feeds(在RSS源中间日期转换成RFC822标准使用)