我正在尝试将我的angular 7服务中的字符串传递给.net API ...,但是它总是会给出错误的Content。谁能建议我任何解决方案?
英语:
#include <string>
#include <vector>
#include <tuple>
#include <iostream>
class geo
{
public:
template<class...Args>
geo(Args&&...);
private:
auto as_tuple() const {
// note: mentioned in lexographical order
return std::tie(_id, name, is_primary, position);
}
friend auto operator ==(geo const& l, geo const& r) -> bool
{
return l.as_tuple() == r.as_tuple();
}
friend auto operator <(geo const& l, geo const& r) -> bool
{
return l.as_tuple() < r.as_tuple();
}
private:
int _id, is_primary;
std::vector<int> position;
std::string name;
};
int main()
{
geo i= geo(2.1, 2.82, 1, 0, 0, 180, 0, "Patient-1",1);
geo j= geo(2.1, 2.82, 1, 0, 0, 180, 0, "Patient-1",1);
if(i==j) {
std::cout<<"they are equal\n";
}
if(i < j) {
std::cout<<"i is less\n";
}
}
API:
searchAgentCode(agent_code:string): Observable<prsProducer[]>{
debugger;
let url: string=this._global.serviceUrl+'Producers/checkAgentCode';
return this._httpClient.post<prsProducer[]>(url,agent_code);
}
答案 0 :(得分:1)
我们可以使用Class对象存储参数。然后将其发送到API。
searchAgentCode(agent_code:string): Observable<prsProducer[]>{
debugger;
Myclass myobj=new Myclass();
myobj.agent_code=agent_code;
let url: string=this._global.serviceUrl+'Producers/checkAgentCode';
return this._httpClient.post<prsProducer[]>(url,myobj);
}
\
对于API,使用相同的属性制作相同的类,并在类对象中接收参数:
[HttpPost]
[Produces(typeof(List<ProducerDC>))]
[Route("checkAgentCode")]
public IActionResult checkAgentCode([FromBody]MyClassforAPI obj_ProducerDC)
{
sys_ACTIVITY_LOG_Insert(Request);
try
{
string agent_code= obj_ProducerDC.agent_code;
//YOUR CODE
}
catch (Exception ex)
{
LogException(ex);
throw new Exception(ex.Message);
}
}
答案 1 :(得分:0)