我在RestTemplate中是全新的,基本上也在REST API中.我想通过Jira REST API在我的应用程序中检索一些数据,但是要取回401 Unauthorized.找到并发表关于jira rest api文档的文章,但实际上并不知道如何将其重写为java,因为该示例使用curl命令行方式.我将不胜感激任何建议或建议如何重写:
curl -D- -X GET -H "Authorization: Basic ZnJlZDpmcmVk" -H "Content-Type: application/json" "http://kelpie9:8081/rest/api/2/issue/QA-31"
Run Code Online (Sandbox Code Playgroud)
使用spring rest模板进入java.其中ZnJlZDpmcmVk是base64编码的username:password字符串.非常感谢你.
我目前正致力于将第三方应用程序与我们的本地报告系统集成.我想用基本身份验证实现REST调用,但在Spring 4.0.0中遇到问题.我有一个简单的解决方案,它很有效:
final RestTemplate restTemplate = new RestTemplate();
final String plainCreds = "username:password";
final byte[] plainCredsBytes = plainCreds.getBytes();
final byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
final String base64Creds = new String(base64CredsBytes);
final HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", "Basic " + base64Creds);
final HttpEntity<String> request = new HttpEntity<String>(headers);
final ResponseEntity<MyDto> response = restTemplate.exchange("myUrl", HttpMethod.GET, request, MyDto.class);
final MyDto dot = response.getBody();
Run Code Online (Sandbox Code Playgroud)
但是想通过以下方式重写这个以使用ClientHttpRequestFactory:
final RestTemplate restTemplate = new RestTemplate(createSecureTransport("username", "password"));
private ClientHttpRequestFactory createSecureTransport(final String username, final String password) {
final HttpClient …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 RabbitMQ HTTP REST 客户端将消息发布到队列中。我正在使用以下网址并请求
http://xxxx/api/exchanges/xxxx/exc.notif/publish
{
"routing_key":"routing.key",
"payload":{
},
"payload_encoding":"string",
"properties":{
"headers":{
"notif_d":"TEST",
"notif_k": ["example1", "example2"],
"userModTime":"timestamp"
}
}
}
Run Code Online (Sandbox Code Playgroud)
并从兔子那里得到以下响应:
{"error":"bad_request","reason":"payload_not_string"}
Run Code Online (Sandbox Code Playgroud)
我只有一个标题集:
Content-Type:application/json
Run Code Online (Sandbox Code Playgroud)
我试图设置
"payload_encoding":"base64",
Run Code Online (Sandbox Code Playgroud)
但它没有帮助。我是兔子的新手,欢迎任何回应。
我刚刚将查询库添加到我的Web应用程序并使用简单警报进行测试:
<script src="<c:url value="/resources/jquery-1.10.2.min.js" />"></script>
<script type="text/javascript">
$(function(){
alert('jquery is working');
});
</script>
Run Code Online (Sandbox Code Playgroud)
并且工作正常.但是当我想在我的下拉列表中实现"更改"事件时
<script src="<c:url value="/resources/jquery-1.10.2.min.js" />"></script>
<script type="text/javascript">
$("#projectKey").change(function() {
alert($('option:selected', $(this)).text());
});
</script>
Run Code Online (Sandbox Code Playgroud)
它没有显示任何警报,基本上没有任何事情发生.我的下拉是以下内容:
<select id="projectKey" name="projectKey">
<option value="AM">AM</option>
<option value="AIL">AIL</option>
<option value="NEB">NEB</option>
<option value="SSP">SSP</option>
</select>
Run Code Online (Sandbox Code Playgroud)
当然我试图简化javascript,只是有
$("#projectKey").change(function() {
alert("test");
});
Run Code Online (Sandbox Code Playgroud)
但仍然没有快乐.这将是选择器或下拉菜单.也试过"select#projectKey"但结果当然是一样的.知道我做错了什么吗?
目前我正在进行我的第一次jquery/ajax调用,我遇到了如何将服务器端结果填充到列表框中的问题.弹簧控制器正确地返回数据(希望如此)我只是在填充列表框时遇到了jquery部分的问题.
这是我的ajax电话
$(function() {
$projectKey = $('#projectKey');
$projectKey.change (
function() {
$.ajax({
type: "GET",
url: "getVersionsByProjectKey",
data: {"projectKey": $projectKey.val() },
dataType: 'json',
success: function(data){
alert('success');
alert(data);
$('#jiraVersion').append(
$('<option></option>').html(data)
);
}
});
}
);
});
Run Code Online (Sandbox Code Playgroud)
这就是我的控制器的样子:
@RequestMapping(value="/getVersionsByProjectKey", method = RequestMethod.GET)
public @ResponseBody List<String> getVersionsByProjectKey(@RequestParam(value = "projectKey") String projectKey) {
List<String> versions = new ArrayList<String>();
versions.add("Chuck");
versions.add("Norris");
versions.add("John");
versions.add("Doe");
return versions;
}
Run Code Online (Sandbox Code Playgroud)
这是我要填充数据的列表框:
<td>
<form:select path="jiraVersion" id="jiraVersion">
</form:select>
</td>
Run Code Online (Sandbox Code Playgroud)
正如我之前所说,我现在只是熟悉jquery并尝试了谷歌的几个解决方案,但没有快乐.我试过了:
success: function(data){
alert('success');
alert(data);
$.each(data, function(index, item) {
$("#jiraVersion").get(0).options[$("#jiraVersion").get(0).options.length] = …Run Code Online (Sandbox Code Playgroud) spring ×3
java ×2
jquery ×2
jsp ×2
resttemplate ×2
ajax ×1
apache ×1
javascript ×1
json ×1
rabbitmq ×1
rest ×1
spring-mvc ×1