Hej,
backend w .net przyjmuje
public ActionResult<IEnumerable<Transaction>> GetCustomers([FromBody] TransactionDto dto){}
czyli np.
{
"salesRepresentativeId": [189],
"start": "2022-01-01",
"end": "2022-01-15"
}
po stronie frontu mam metodę w api serwisie
/**
* @description set the POST HTTP request
* @param resource: string
* @param params: AxiosRequestConfig
* @returns Promise<AxiosResponse>
*/
public static post(resource: string, params: AxiosRequestConfig): Promise<AxiosResponse> {
return ApiService.vueInstance.axios.post(`${resource}`, params);
}
używam akurat Vue ale to raczej nie ma znaczenia
setup() {
const testParams = {
SalesRepresentativeId: [189],
Start: "2022-04-21",
End: "2022-04-21",
};
let transactions = reactive({});
onMounted(() => {
ApiService.post("api/dev/transactions", {data:testParams)
.then(({ data }) => {
transactions = data;
})
.catch(({ response }) => {
//
});
});
return {
transactions,
};
},
z backendu dostaję 400 required SalesRepresentativeId. Wszystko rozumiem dlaczego ... natomiast chciałbym zacząć tego używać przy jak najmniejszych modyfikacjach tzn. backend przyjmuje obiekt (dto) nie chciałbym tego zmieniać, frontend chce to słać jako data:{object}, Jakbyście to ruszyli?
zarzucę jeszcze tym aby mieć ogląd na metodę post serwisu
export interface AxiosRequestConfig {
url?: string;
method?: Method;
baseURL?: string;
transformRequest?: AxiosTransformer | AxiosTransformer[];
transformResponse?: AxiosTransformer | AxiosTransformer[];
headers?: any;
params?: any;
paramsSerializer?: (params: any) => string;
data?: any;
timeout?: number;
timeoutErrorMessage?: string;
withCredentials?: boolean;
adapter?: AxiosAdapter;
auth?: AxiosBasicCredentials;
responseType?: ResponseType;
xsrfCookieName?: string;
xsrfHeaderName?: string;
onUploadProgress?: (progressEvent: any) => void;
onDownloadProgress?: (progressEvent: any) => void;
maxContentLength?: number;
validateStatus?: ((status: number) => boolean) | null;
maxBodyLength?: number;
maxRedirects?: number;
socketPath?: string | null;
httpAgent?: any;
httpsAgent?: any;
proxy?: AxiosProxyConfig | false;
cancelToken?: CancelToken;
decompress?: boolean;
transitional?: TransitionalOptions
}