大家好我在Angular上创建HTTP请求,但我不知道如何添加url参数(查询字符串).
this.http.get(StaticSettings.BASE_URL).subscribe(
(response) => this.onGetForecastResult(response.json()),
(error) => this.onGetForecastError(error.json()),
() => this.onGetForecastComplete()
);
Run Code Online (Sandbox Code Playgroud)
现在我的StaticSettings.BASE_URL就像一个没有查询字符串的网址,如:http://atsomeplace.com/ 但我希望它是http://atsomeplace.com/?var1=val1&var2=val2
哪个var1和var2适合我的Http请求对象?我想像对象一样添加它们.
{
query: {
var1: val1,
var2: val2
}
}
Run Code Online (Sandbox Code Playgroud)
然后只是Http模块完成工作将其解析为URL查询字符串.
我在使用带有Angular 2的RxJS时遇到了问题.从Typescript定义文件中建议的大多数方法都没有在我的Observable对象上定义,比如......
然后我想通了,Observable原型上不存在方法.
我知道很多东西从版本4改为5,所以我想念一些东西吗?
我想写一个 HTTP 实现。
几天来,我一直在寻找关于使用Content-Type: multipart/form-data.
我已经在 stackoverflow 上查看了很多关于它的问题,例如:
HTTP 文件上传是如何工作的?
enctype='multipart/form-data' 是什么意思?
我深入研究了 RFC 2616(和更新版本)、2046 等。但我没有找到明确的答案(显然我没有得到它背后的想法)。
在大多数文章和答案中,我发现了这段请求字符串,这对我来说很容易解释,所有这些都记录在 RFC 中...
POST /upload?upload_progress_id=12344 HTTP/1.1
Host: localhost:3000
Content-Length: 1325
Origin: http://localhost:3000
... other headers ...
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryePkpFF7tjBAqx29L
------WebKitFormBoundaryePkpFF7tjBAqx29L
Content-Disposition: form-data; name="MAX_FILE_SIZE"
100000
------WebKitFormBoundaryePkpFF7tjBAqx29L
Content-Disposition: form-data; name="uploadedfile"; filename="hello.o"
Content-Type: application/x-object
... contents of file goes here ...
------WebKitFormBoundaryePkpFF7tjBAqx29L--
Run Code Online (Sandbox Code Playgroud)
...并且实现一个 HTTP 客户端以在任何语言中以这种方式构造一段字符串会很简单。
问题变成了... contents of file goes here ...,关于“文件内容”的信息很少。我知道它是具有某种类型和编码的二进制数据,但是很难想到字符串数据,我将如何添加一段在字符串中没有字符串表示的二进制数据。
我想看到任何语言的 HTTP 协议的低级实现示例。或许还有关于通过 HTTP 传输二进制数据、客户端如何创建请求以及服务器如何读取/解析它的深入解释。
PD。我知道这个问题我看起来很重复,但大多数答案并不集中在解释二进制数据传输(如媒体)上。
这是问题:我有一个服务在构造函数中发出HTTP请求:
constructor(public http: Http, public geolocation: Geolocation) {
this.http = http;
this.geolocation = geolocation;
//Http request... this will set variable forecast of the class when complete.
this.getForecast(16);
}Run Code Online (Sandbox Code Playgroud)
然后我在这样的组件中注入该服务:
constructor(public connector: ApiConnector) {
this.forecast = connector.forecast;
}Run Code Online (Sandbox Code Playgroud)
如果我尝试在组件装饰器上使用组件类的预测成员,就像我在这里一样:
@Component({
selector: 'app',
directives: [MainForecast, DailyForecast],
template: `
<main-forecast [main-weather]="forecast"></main-forecast>
<daily-forecast [weather-list]="forecast.list"></daily-forecast>
`,
})Run Code Online (Sandbox Code Playgroud)
我收到一个错误,"无法读取未定义的属性'列表'......"
是否有可能在组件构造函数中使用promises?
我刚刚改用新的ASP.NET 5平台.我使用visual studio代码作为我的默认IDE,并使用DNX执行..NET Core现在默认情况下,但我需要切换到.NET Framework,我想引用System.Data.Entity命名空间或TodoContext类.
无论如何在.NET Core中使用EF?
这就是我现在正在做的事情.

我有一个简单的指令,根据接收的属性为给定的HTML元素添加一些属性.
<button class="btn btn-blue x-large" [myDirective]="{ some_json_data: true }">
Unfold
</button>
Run Code Online (Sandbox Code Playgroud)
该myDirective指令只是在ngOnInit钩子中做了一些逻辑并装饰了ElementRef原生元素(在这种情况下是按钮)添加属性,没有什么复杂的.
ngOnInit(): void {
const el: Element = this.element.nativeElement;
this.decorate(el, this.myDirective);
}
Run Code Online (Sandbox Code Playgroud)
基于给定的逻辑(在myDirective装饰中)我想向ElementRefat 引用的元素添加工具提示(这是另一个指令)myDirective.
如何手动挂载指令以及如何将其添加到元素(ViewContainerRef)?
我正在使用 Typescript 使用 Redux 和 Maquettejs 开发一个待办事项应用程序示例。我只是编译 typescript,然后使用 browserify 捆绑所有 .js 文件(该文件包含应用程序 .ts 文件和库 [redux、maquettejs]),编译时没有错误,一切正常。
当我尝试在浏览器上查看结果时出现此错误,问题就出现了。
至少对我来说这是没有意义的,因为它是明确定义的。我不是判断编译代码的专家,但万一我创建了一个模拟实现http://jsbin.com/tenohitumi/edit?js,console,output并且它按预期工作。我真的不明白发生了什么事。
以防万一这是用打字稿编写的“App”类。
import { h, VNodeProperties, VNode } from 'maquette';
import { Store } from 'redux';
import { TodoList } from './Todolist';
export class App {
constructor(private store: Store<any>) {
}
render(): VNode {
this.store;
return h('div.main-component', [
new TodoList(this.store).render()
]);
}
}
// This is how I create the instance (it's in a different file)
import { createStore } from 'redux'; …Run Code Online (Sandbox Code Playgroud)我正在尝试将闭包发送到线程中进行处理,例如:
fn spawn<F>(work_load: F) where F: FnMut() {
let builder = Builder::new();
let handler = builder.spawn(move || {
// Before process
work_load();
// After process
}).unwrap();
}
Run Code Online (Sandbox Code Playgroud)
但我收到错误:
F无法在线程之间安全发送
在高度概述中,我需要这样做(代码编译):
let closure = || env_variable.to_string();
thread::spawn(move || {
// before closure
closure();
// after closure
});
Run Code Online (Sandbox Code Playgroud)
F考虑到我需要捕获环境,我如何定义才能将其发送到线程中。
typescript ×5
angular ×4
http ×4
javascript ×2
.net-core ×1
asp.net ×1
browserify ×1
c# ×1
closures ×1
maquette ×1
networking ×1
promise ×1
protocols ×1
redux ×1
rust ×1
rxjs ×1
sockets ×1