我正在尝试使用HTTP身份验证在线发布玩家得分,但响应总是401(未经授权),尽管我非常确定用户名和密码是否正确.我究竟做错了什么?
DefaultHttpClient client = new DefaultHttpClient();
Credentials creds = new UsernamePasswordCredentials("user", "passsword");
client.getCredentialsProvider().setCredentials(new AuthScope("http://myurl.com/score.php", 80), creds);
try {
HttpPost post = new HttpPost("http://myurl.com/score.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
nameValuePairs.add(new BasicNameValuePair("score", points));
nameValuePairs.add(new BasicNameValuePair("name", name));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = client.execute(post);
final int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
throw new Exception();
}
} catch (UnsupportedEncodingException e) {
//
} catch (IOException e) {
//
} catch (Exception e) {
//
}
Run Code Online (Sandbox Code Playgroud)
我的代码出了什么问题?
我正在尝试使用Google的.NET Calendar API 检索南非公众假期.
我有以下问题:
EventQuery范围.(在给定日期范围之前和之后)我通过在线查看确认了这个特定的公共日历具有正确的日期.
我最好的猜测是我错误地使用了API,并且我正在查询日历条目的创建/更新日期而不是事件日期.
码:
var feedUrl = "http://www.google.com/calendar/feeds/en.sa%23holiday%40group.v.calendar.google.com/public/full";
var service = new CalendarService("My application name");
var qry = new EventQuery(feedUrl);
qry.StartDate = new DateTime(2011, 1, 1);
qry.EndDate = new DateTime(2012, 1, 1);
EventFeed results = service.Query(qry);
foreach (EventEntry entry in results.Entries)
{
if (entry.Times.Count == 0)
continue;
// Using entry.Times[0].StartTime results in
// missing data and data outside of the given search criteria.
}
Run Code Online (Sandbox Code Playgroud)
我使用的是最新的Google .NET Data …
如果特定的类不是元素的子元素,我需要将一个样式应用于元素.
<table class="printlist" style="width:100%">
<tbody>
<tr class="list_wanted0"><td>Whatever...</td></tr>
<tr class="list_wanted1"><td>
<div class="journal">
<table><tbody>
<tr><td style="width: 9em">2011-03-12 09:36</td></tr>
</tbody></table>
</div>
</td></tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
上面的例子减少到最小,以证明结构.
我要的是有:Hover属性只适用.printlist tr,如果<tr>有NO .journal孩子.
该.list_wanted0和.list_wanted1不能被用来选择.journal,也可以是其他类名存在.
我试过的CSS是:
.printlist tr:Hover * :not(itemjournal) {
color: #000;
background: #aaa
}
Run Code Online (Sandbox Code Playgroud)
显然,这不符合我的意图.
如果您需要更多信息,请不要犹豫,
谢谢.
上周我发现了Guice ...我正在尝试一些简单的技巧.但是,我目前被封锁......
我正在尝试将请求转发到由包含" * " 的url-pattern服务的Servlet中的JSP .但我一直收到"错误404":(
一步步 :
ServletModule :
serve("/test/*").with(TestServlet.class);
Run Code Online (Sandbox Code Playgroud)
TestServlet :
public void doGet(HttpServletRequest req, HttpServletResponse resp)
{
System.err.println("Start");
try
{
req.getRequestDispatcher("/WEB-INF/layout/test.jsp").forward(req, resp);
}
catch (Exception e)
{
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
HTTP错误404
访问/WEB-INF/layout/test.jsp时出现问题.原因:/
WEB-INF/layout/test.jsp
我测试了"serve("/ test").with(TestServlet.class);" 它工作
我没有Guice测试(通过在web.xml中定义servlet),它工作...
感谢阅读!
我已经尝试寻找我的问题的答案,但我找不到一个没有重新排序数字索引.
有没有办法将字符串添加到数组的开头而无需重新排序键(数字键)而不使用循环?
谢谢
编辑:
我会尝试解释这个场景.(我正在使用CodeIgniter).
我有一个在我的应用程序中使用的数组.此数组还用于创建下拉列表并以我拥有的形式验证这些下拉列表值.我想要做的是在数组的开头插入一个空值,以便我的下拉列表默认选择一个空白选项.
所以从此
1 => Hello
2 =>世界
至
''=>''
1 => Hello
2 =>世界
我们正在使用Mustache模板,我想在我们的RoR Web应用程序中创建一个预览View,它将模板和我们存储在数据库中的一些数据结合起来,但它不能像我预期的那样工作,并且在对互联网进行一些搜索之后(包括所以!),我没有找到包含活动模型的任何示例.
如何将ActiveModel记录传递给Mustache以与模板合并?
设置:
架构
create_table "templates", :force => true do |t|
t.string "kind"
t.text "data"
t.integer "data_count"
end
create_table "bars", :force => true do |t|
t.string "guid"
t.string "name"
t.string "summary"
end
Run Code Online (Sandbox Code Playgroud)
这些模型没有什么特别之处.两者都是ActiveRecord :: Base的子类
class Bars < ActiveRecord::Base
end
class Templates < ActiveRecord::Base
end
Run Code Online (Sandbox Code Playgroud)
控制器
class TemplateController < ApplicationController
def preview
@result = Mustache.render( template.data, :bars => Bar.limit(template.data_count ) ).html_safe
end
end
Run Code Online (Sandbox Code Playgroud)
风景
<%= @result %>
Run Code Online (Sandbox Code Playgroud)
路线
get 'templates/:id/preview' => 'templates#preview', :as => 'templates_preview'
Run Code Online (Sandbox Code Playgroud)
数据
y …Run Code Online (Sandbox Code Playgroud) 使用posix read()write()linux调用,是否保证如果我通过一个文件描述符写入并通过另一个文件描述符读取,则以串行方式使这两个动作相互排斥......我的读文件描述符总是会看到写文件描述符最后写的是什么?
我相信情况确实如此,但我想确定并且手册页对此没有太大帮助
<div style="float: left; margin-top: 10px; font-family: Verdana; font-size: 13px; color: #404040;">innertext</div>
Run Code Online (Sandbox Code Playgroud)
我可以访问没有class或id但span使用简单的 html dom php 解析器的 div 的内部文本吗?谢谢。
嗨,我编写了一些C#,但从未使用过数据库.我想在一些框架中使用带有C#的SQL Server.微软似乎在C#的整个生命周期中都提供了许多框架.这使我很难搜索/选择.
我应该选择哪一个?我正在开发一个简单的3层webapp.我看过一些Entity Framework .Net 4.0视频,但我觉得事情太自动了.我现在需要做一些SQL ..
如果我应该去EF4.0,这真的是最好的参考http://msdn.microsoft.com/en-us/library/bb386876.aspx
有什么建议?
如果我通过Java得到一个进程对象Runtime.getRuntime().exec(...),或者ProcessBuilder.start(),我可以等待它Process.waitFor(),就像是Thread.join(),或者我可以用它来杀死它Process.destroy(),就像被弃用的那样Thread.stop().
但是:我如何找到过程对象的pid?我在官方文档中没有看到这样做的方法.我可以用Java做到这一点吗?如果是这样,怎么样?