我在MonoDroid中使用Webrequests并随机获取超时时遇到了很多麻烦.我的代码工作正常,有时所有请求只是超时,不起作用.
我已经验证了我的请求中使用的Web服务不是问题.
下面是一些代码的示例,我可以使用它来从使用MonoDroid的Web服务请求一些数据:
bool bolOk = false;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create ("http://www.website.com/service/");
request.Timeout = 20000;
request.Credentials = gv_objCredentials;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse ()) {
bolOk = response.StatusCode == HttpStatusCode.OK;
}
Run Code Online (Sandbox Code Playgroud)
你可以看到它是基本的东西.我使用ThreadPool.QueueUserWorkItem或TaskFactory使用上面的代码总是在另一个线程上使用UI.
我注意到的是,如果请求从我的应用程序开始超时,我将其插入我的计算机,然后从MonoDevelop调试应用程序,请求工作没有超时.我不确定这是否意味着什么.这类似于使用与手机在同一网络上的浏览器从我的计算机测试Web服务.Web服务始终可以正常工作.
从MonoDroid制作Webrequest的最佳方法是什么?
如何确保我的请求始终成功,并且如果Web服务正常运行,则不会超时?
我有一个在中心ListView使用a 的项目布局HorizontalScrollView.我android:descendantFocusability="blocksDescendants"在父母身上使用了android属性" ",LinearLayout这样ListView项目仍然可以选择.
我遇到的问题是,点击的一部分时,ListView这是该项目HorizontalScrollView时,ListView不叫产品Click事件.
如何获取HorizontalScrollView调用ListView列表项单击事件的click事件?
我需要将一个ics文件上传到REST API.给出的唯一示例是curl命令.
用于使用curl上传文件的命令如下所示:
curl --user {username}:{password} --upload-file /tmp/myappointments.ics http://localhost:7070/home/john.doe/calendar?fmt=ics
Run Code Online (Sandbox Code Playgroud)
如何在C#中使用HttpWebRequest执行此操作?
另请注意,我可能只将ics作为字符串(而不是实际文件).
我在ASP.Net应用程序中使用支付网关API.使用XSP在MonoDevelop中进行测试时,应用程序可以正常运行.当我将其配置为使用mod_mono在apache2中运行时,代码会因超时错误而崩溃.
我很遗憾在Apache中托管而不是XSP可以改变什么.无论如何,下面的代码是超时:
private string SubmitXml(string InputXml)
{
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(_WebServiceUrl);
webReq.Method = "POST";
byte[] reqBytes;
reqBytes = System.Text.Encoding.UTF8.GetBytes(InputXml);
webReq.ContentType = "application/x-www-form-urlencoded";
webReq.ContentLength = reqBytes.Length;
webReq.Timeout = 5000;
Stream requestStream = webReq.GetRequestStream();
requestStream.Write(reqBytes, 0, reqBytes.Length);
requestStream.Close();
HttpWebResponse webResponse = (HttpWebResponse)webReq.GetResponse();
using (StreamReader sr = new StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.ASCII))
{
return sr.ReadToEnd();
}
}
Run Code Online (Sandbox Code Playgroud)
代码崩溃了: Stream requestStream = webReq.GetRequestStream();
返回的错误是:
请求超时
描述:HTTP 500.错误处理请求.
堆栈跟踪:
System.Net.WebException:请求在/private/tmp/monobuild/build/BUILD/mono-2.10.9/mcs/class/System/System.Net中的System.Net.HttpWebRequest.GetRequestStream()[0x0005f]超时/ HttpWebRequest.cs:746 at TCShared.PxPay.SubmitXml(System.String InputXml)[0x00048]/TCShared.PxPay /Users/liam/Projects/techcertain/techcertaincsharp/Components/TCShared/PaymentGateways/Client/PxPay.cs:85 .GenerateRequest(TCShared.RequestInput输入)[0x00015]在/Users/liam/Projects/techcertain/techcertaincsharp/Components/TCShared/PaymentGateways/Client/PxPay.cs:69
在我的Web.Config中,我有以下作为请求超时:
<httpRuntime executionTimeout="43200" maxRequestLength="104856" requestValidationMode="2.0" />
Run Code Online (Sandbox Code Playgroud)
我已经尝试在HttpWebRequest上更改Timeout值,但它仍然是超时的.
是什么导致这种情况发生,我该如何解决?
我想在父对象的显示视图中以表的形式显示一组相关的has_many对象。
当前,has_many项仅被显示为以逗号分隔的列表。
如何将has_many项目显示为表格并指定要包括的列?
我正在使用rails 4.1.
我已经设置了自定义控制器.我已经配置了以下路线:
resources :chats
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用jQuery向控制器发出post请求.这是代码:
$.post('/chats/', { session: { advisor_id: $(this).attr('data-id') } }, function (data) {
eval(data);
});
Run Code Online (Sandbox Code Playgroud)
编辑:这是我的控制器的代码 -
class ChatsController < ApplicationController
def create
#create the new session
@session = Session.create(:advisor_id => session_params[:advisor_id], :session_type => @session.call!, :client_id => current_user.id)
end
private
def session_params
params[:session].permit(:advisor_id, :client_id, :session_type)
end
end
Run Code Online (Sandbox Code Playgroud)
编辑:这是我的模型的代码 -
class Session < ActiveRecord::Base
enum session_type: [ :chat, :call ]
belongs_to :client, :class_name => "User", :foreign_key => :client_id
belongs_to :advisor, :class_name => "User", :foreign_key => :advisor_id
has_many …Run Code Online (Sandbox Code Playgroud) 我想在不干扰本地分支的情况下将新添加的远程分支引入我的本地存储库。这可能吗?
当我做:
git branch -a
Run Code Online (Sandbox Code Playgroud)
新的远程分支没有出现在列表中。因此,如果我尝试获取 origin/newremotebranch,它会说它不存在。
我团队中的开发人员将更改提交到了错误的远程存储库.我想删除他推送到远程存储库上的此存储库的内容.我不想在当地改变任何东西.
因此我怎么能:
列出远程存储库分支上的提交,以便我可以看到需要删除哪些已推送的提交.
删除远程存储库分支上的每个提交,以便我可以在推送更改之前返回到提交.
我不确定"删除"是否是正确的过程,或者它是否意味着"恢复"但最终我需要远程存储库分支回到他推动他的更改之前的位置.
我正在转换一些Java代码C#,以便在我的MonoDroid应用程序中使用.我有一些片段,其中声明接口,然后初始化为对象.我不是100%肯定在C#中实现这些的最佳方法.
例如:
public class NumberPicker {
public interface Formatter {
String toString(int value);
}
public static final NumberPicker.Formatter TWO_DIGIT_FORMATTER =
new NumberPicker.Formatter() {
//some code here
};
}
Run Code Online (Sandbox Code Playgroud)
在c#中执行此操作的等效或最佳方法是什么?
我正在使用JSON API,它以下列格式将datetime值作为字符串返回:
/日期(1370651105153)/
如何将这样的值解析为rails中的datetime变量?